Results 1 to 3 of 3

Thread: Ask password via console.readline

  1. #1
    whitespire is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Nov 2004
    Posts
    7
    Reputation
    0

    Unhappy Ask password via console.readline

    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

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,626
    Reputation
    2739
    Use Console.ReadKey(True) method to read the chars and conceal them.
    Code:
    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()

  3. #3
    whitespire is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Nov 2004
    Posts
    7
    Reputation
    0
    Thanks !!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking