473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 11335
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*********@hotmail.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.Key != ConsoleKey.Enter)
{
if(nextKey.Key == ConsoleKey.BackSpace)
{
if(password.Length 0)
{
password.RemoveAt(password.Length - 1);

// erase the last * as well
Console.Write(nextKey.KeyChar);
Console.Write(" ");
Console.Write(nextKey.KeyChar);
}
}
else
{
password.AppendChar(nextKey.KeyChar);
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.Key != ConsoleKey.Enter)
{
if(nextKey.Key == ConsoleKey.BackSpace)
{
if(password.Length 0)
{
password.RemoveAt(password.Length - 1);

// erase the last * as well
Console.Write(nextKey.KeyChar);
Console.Write(" ");
Console.Write(nextKey.KeyChar);
}
}
else
{
password.AppendChar(nextKey.KeyChar);
Console.Write("*");
}

nextKey = Console.ReadKey(true);
}

Console.WriteLine();

// lock the password down
password.MakeReadOnly();
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*********@hotmail.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.Enter
If nextKey.Key = ConsoleKey.BackSpace Then
If password.Length 0 Then
password.RemoveAt(password.Length - 1)

' erase the last * as well
Console.Write(nextKey.KeyChar)
Console.Write(" ")
Console.Write(nextKey.KeyChar)
End If
Else
password.AppendChar(nextKey.KeyChar)
Console.Write("*")
End If

nextKey = Console.ReadKey(True)
Loop

Console.WriteLine()

' lock the password down
password.MakeReadOnly()
Return password

Hope that helps
Martin
ju*********@hotmail.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.Key != ConsoleKey.Enter)
{
if(nextKey.Key == ConsoleKey.BackSpace)
{
if(password.Length 0)
{
password.RemoveAt(password.Length - 1);

// erase the last * as well
Console.Write(nextKey.KeyChar);
Console.Write(" ");
Console.Write(nextKey.KeyChar);
}
}
else
{
password.AppendChar(nextKey.KeyChar);
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.Key != ConsoleKey.Enter)
{
if(nextKey.Key == ConsoleKey.BackSpace)
{
if(password.Length 0)
{
password.RemoveAt(password.Length - 1);

// erase the last * as well
Console.Write(nextKey.KeyChar);
Console.Write(" ");
Console.Write(nextKey.KeyChar);
}
}
else
{
password.AppendChar(nextKey.KeyChar);
Console.Write("*");
}

nextKey = Console.ReadKey(true);
}

Console.WriteLine();

// lock the password down
password.MakeReadOnly();
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*********@hotmail.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
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
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...
2
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...
9
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
by: Emaga75 | last post by:
In dotNET windows_based deployment project user interface form, How to mask a textbox for input password? Thanks.
4
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...
0
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...
1
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.