473,554 Members | 4,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to mask console password input

Hey,

Currently I'm writing a VB.NET/1.1 app and I need to mask the input for
the password field. Does anyone know how to do this in VB? I've seen a
C# example, but wouldn't know how to convert it myself. Here's the URL:
http://www.codeproject.com/dotnet/Co...swordInput.asp

Aug 14 '06 #1
3 11355
Hi Julian

One of the comments in the codeproject entry you've listed points to a
blog entry that does exactly what you're asking for using SecureString
- take a look at
http://blogs.msdn.com/shawnfa/archiv...27/143254.aspx which
seems to be what you're after.

hope that helps
Martin
ju*********@hot mail.com wrote:
Hey,

Currently I'm writing a VB.NET/1.1 app and I need to mask the input for
the password field. Does anyone know how to do this in VB? I've seen a
C# example, but wouldn't know how to convert it myself. Here's the URL:
http://www.codeproject.com/dotnet/Co...swordInput.asp
Aug 14 '06 #2
Hi Pritcham,

Thanks for replying to my message, but the example in the MSDN blog
seems to be describing a Whidbey (VB.NET 2005) sample and I'm currently
using VB.NET 2003. The code on there doesn't make any sense to me.
Could you possibly convert this to VB.NEt 2003 for me? I just need the
masking part from below such as:

while(nextKey.K ey != ConsoleKey.Ente r)
{
if(nextKey.Key == ConsoleKey.Back Space)
{
if(password.Len gth 0)
{
password.Remove At(password.Len gth - 1);

// erase the last * as well
Console.Write(n extKey.KeyChar) ;
Console.Write(" ");
Console.Write(n extKey.KeyChar) ;
}
}
else
{
password.Append Char(nextKey.Ke yChar);
Console.Write(" *");
}

nextKey = Console.ReadKey (true);
}

.... and below is the full example:

public static SecureString GetPassword()
{
SecureString password = new SecureString();

// get the first character of the password
ConsoleKeyInfo nextKey = Console.ReadKey (true);

while(nextKey.K ey != ConsoleKey.Ente r)
{
if(nextKey.Key == ConsoleKey.Back Space)
{
if(password.Len gth 0)
{
password.Remove At(password.Len gth - 1);

// erase the last * as well
Console.Write(n extKey.KeyChar) ;
Console.Write(" ");
Console.Write(n extKey.KeyChar) ;
}
}
else
{
password.Append Char(nextKey.Ke yChar);
Console.Write(" *");
}

nextKey = Console.ReadKey (true);
}

Console.WriteLi ne();

// lock the password down
password.MakeRe adOnly();
return password
}
Pritcham wrote:
Hi Julian

One of the comments in the codeproject entry you've listed points to a
blog entry that does exactly what you're asking for using SecureString
- take a look at
http://blogs.msdn.com/shawnfa/archiv...27/143254.aspx which
seems to be what you're after.

hope that helps
Martin
ju*********@hot mail.com wrote:
Hey,

Currently I'm writing a VB.NET/1.1 app and I need to mask the input for
the password field. Does anyone know how to do this in VB? I've seen a
C# example, but wouldn't know how to convert it myself. Here's the URL:
http://www.codeproject.com/dotnet/Co...swordInput.asp
Aug 14 '06 #3
How about something like the following:

Public Shared Function GetPassword() As SecureString
Dim password As New SecureString()

' get the first character of the password
Dim nextKey As ConsoleKeyInfo = Console.ReadKey (True)

Do While nextKey.Key <ConsoleKey.Ent er
If nextKey.Key = ConsoleKey.Back Space Then
If password.Length 0 Then
password.Remove At(password.Len gth - 1)

' erase the last * as well
Console.Write(n extKey.KeyChar)
Console.Write(" ")
Console.Write(n extKey.KeyChar)
End If
Else
password.Append Char(nextKey.Ke yChar)
Console.Write(" *")
End If

nextKey = Console.ReadKey (True)
Loop

Console.WriteLi ne()

' lock the password down
password.MakeRe adOnly()
Return password

Hope that helps
Martin
ju*********@hot mail.com wrote:
Hi Pritcham,

Thanks for replying to my message, but the example in the MSDN blog
seems to be describing a Whidbey (VB.NET 2005) sample and I'm currently
using VB.NET 2003. The code on there doesn't make any sense to me.
Could you possibly convert this to VB.NEt 2003 for me? I just need the
masking part from below such as:

while(nextKey.K ey != ConsoleKey.Ente r)
{
if(nextKey.Key == ConsoleKey.Back Space)
{
if(password.Len gth 0)
{
password.Remove At(password.Len gth - 1);

// erase the last * as well
Console.Write(n extKey.KeyChar) ;
Console.Write(" ");
Console.Write(n extKey.KeyChar) ;
}
}
else
{
password.Append Char(nextKey.Ke yChar);
Console.Write(" *");
}

nextKey = Console.ReadKey (true);
}

... and below is the full example:

public static SecureString GetPassword()
{
SecureString password = new SecureString();

// get the first character of the password
ConsoleKeyInfo nextKey = Console.ReadKey (true);

while(nextKey.K ey != ConsoleKey.Ente r)
{
if(nextKey.Key == ConsoleKey.Back Space)
{
if(password.Len gth 0)
{
password.Remove At(password.Len gth - 1);

// erase the last * as well
Console.Write(n extKey.KeyChar) ;
Console.Write(" ");
Console.Write(n extKey.KeyChar) ;
}
}
else
{
password.Append Char(nextKey.Ke yChar);
Console.Write(" *");
}

nextKey = Console.ReadKey (true);
}

Console.WriteLi ne();

// lock the password down
password.MakeRe adOnly();
return password
}
Pritcham wrote:
Hi Julian

One of the comments in the codeproject entry you've listed points to a
blog entry that does exactly what you're asking for using SecureString
- take a look at
http://blogs.msdn.com/shawnfa/archiv...27/143254.aspx which
seems to be what you're after.

hope that helps
Martin
ju*********@hot mail.com wrote:
Hey,
>
Currently I'm writing a VB.NET/1.1 app and I need to mask the input for
the password field. Does anyone know how to do this in VB? I've seen a
C# example, but wouldn't know how to convert it myself. Here's the URL:
http://www.codeproject.com/dotnet/Co...swordInput.asp
Aug 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7391
by: IronMan | last post by:
Anyway to put an input mask for an input box? *****CODE***** Dim strPasswd strPasswd = InputBox("Please Enter Password", "Password Protected Form") *****CODE*****
2
7055
by: Francis Debrabandere | last post by:
Hi all, I'm a beginner in ms access, and I'm working on my first real application. But to finish it up I'm facing a problem. I'm not able to solve and maybe someone can help me. I have made a database that can be divided in two major parts: 1. entering data 2. reading the entered data. Everybody who uses the database has access to the...
2
11322
by: Yang | last post by:
Hi Is it possible to mask console input in a c# console application? What I mean is: if I entered string "test" in the console, it'll echo "****"(or nothing) instead of the string "test". I've tried setting the foregroud color of the console the same as the backgroud color through native API, but it doesn't really hide the password,...
9
11482
by: msnews.microsoft.com | last post by:
Hello. How can I set input mask for TextBox? Or can I use for mask input some other control?
1
1678
by: Emaga75 | last post by:
In dotNET windows_based deployment project user interface form, How to mask a textbox for input password? Thanks.
4
7849
by: kimso.zhao | last post by:
Hi All, I need a function that when user types a password in the console, the password should be invisible (e.g. display nothing or display "*" instead). Just as you can see when you login a machine. How to implement this? Thanks! Note: user is typing passord in the console.
0
1701
by: gibsonsgman | last post by:
Hello, I have a form with a text field on it. I have applied the 'Password' input mask because it is a password field. However, when I enter the correct password, it says the password is incorrect. If i take the input mask off it works. Is there any reason why this would happen? Here is my code if that helps. If strInput = strpassword...
1
5121
by: Ntl News Group | last post by:
I have an Access InputBox, when the user enters the text into the strInput I want it to appear as **** like when the Input Mask of Password is selected on a Forms Text Box. Any Ideas? Many Thanks
5
16950
by: theunsgoosen | last post by:
Access beginner, Hi, Im using code to unlock information so the user can change the information. I also need the input mask to change from "password" to "text", but im struggling with that specific part of the code. Thanks Theuns Private Sub EmployeeCode_Enter() Dim strInput As String, strMsg As String strMsg = "'Action code'is...
0
7539
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7581
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7897
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5446
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3589
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1149
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
858
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.