Ask password via console.readline

whitespire

Member
Joined
Nov 13, 2004
Messages
7
Programming Experience
Beginner
Making a console application. Need to ask for a password. Which is the best way to do this considering I do not want the password to echo to the screen.

Thanks
 
Use Console.ReadKey(True) method to read the chars and conceal them.
VB.NET:
Console.Write("Password: ")
Dim password As String = String.Empty
Dim info As ConsoleKeyInfo
Do
    info = Console.ReadKey(True)
    If info.Key = ConsoleKey.Enter Then
        Exit Do
    Else
        password &= info.KeyChar
        Console.Write("*"c)
    End If
Loop
Console.WriteLine()
Console.WriteLine("you wrote: " & password)
Console.ReadKey()
 
Back
Top