472,371 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 11153
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.