DEV Community

Cover image for VB .Net: PasswordFromKeys
vblover programmer
vblover programmer

Posted on

VB .Net: PasswordFromKeys

Method:

    Function PasswordFromKeys() As String
        Dim Key As ConsoleKeyInfo
        Dim Expr As String = ""
        Do
            Key = Console.ReadKey(True)
            Select Case Key.Key
                Case ConsoleKey.Enter
                    Exit Do
                Case ConsoleKey.Escape
                    Return ""
                Case ConsoleKey.Backspace
                    If Expr.Length = 0 Then Continue Do
                    Expr = Expr.Remove(Expr.Length - 1, 1)
                    Console.Write("{0} {0}", Key.KeyChar)
                Case ConsoleKey.NumPad0 To ConsoleKey.NumPad9,
                     ConsoleKey.D0 To ConsoleKey.D9,
                     ConsoleKey.A To ConsoleKey.Z
                    Expr += Key.KeyChar
                    Console.Write("*")
                Case Else
                    Continue Do
            End Select
        Loop
        Return Expr
    End Function
Enter fullscreen mode Exit fullscreen mode

Using:

Console.ForegroundColor = ConsoleColor.White
Console.Write("{0} Type Password: ", vbTab)
Console.ForegroundColor = ConsoleColor.Green
Dim Password As String = PasswordFromKeys()
Console.WriteLine()
Console.ForegroundColor = ConsoleColor.White
Console.Write("{0} Your Password is: ", vbTab)
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("{0}", Password)
Enter fullscreen mode Exit fullscreen mode

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay