473,692 Members | 2,149 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 11368
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
7400
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
7061
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 second part. The
2
11326
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, actually, users can manually change the foregroud color in a windows console window, or they can copy the...
9
11497
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
1685
by: Emaga75 | last post by:
In dotNET windows_based deployment project user interface form, How to mask a textbox for input password? Thanks.
4
7875
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
1718
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 And frmDisableandEnable.Value = 1 Then SetProperties "AllowBypassKey", dbBoolean, True Beep...
1
5147
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
17015
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 password protected."
0
8540
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9086
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8963
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8806
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4324
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2241
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1959
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.