Masked password + MD5 encryption-VBForums
Results 1 to 2 of 2

Thread: Masked password + MD5 encryption

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    5

    Masked password + MD5 encryption

    Hello, I'm making a console application with a login. The system I have now is extremely basic and very redundant. I would like the password to be masked as you type it in "*****" for example and If possible I would like to encrypt the password with md5. Can someone let me know how to/give me the code to do it.

    This is my current login system:
    Code:
    Sub LogIn()
            'A log in system to prevent unwanted users from acsessing the system
            Console.Write("Username: ")
            Dim username As String = Console.ReadLine.ToLower
            If username = "sian" Then
                loginPassword()
                'If the username is correct it goes on to the main screen.
            Else
                'If the username is wrong it loops back into the log in
                Console.Clear()
                LogIn()
            End If
            End
        End Sub
    
        'If the password is correct it goes on to ask for the password
        Sub loginPassword()
            Console.Write("Password: ")
            Dim Password As String = Console.ReadLine.ToLower
            If Password = "password" Then
                Console.Clear()
                options()
                'If the password is correct it leads into the options
            Else
                'If the password is wrong it loops back into the log in
                Console.Clear()
                LogIn()
            End If
            End
        End Sub

  2. #2
    Addicted Member Cimperiali's Avatar
    Join Date
    Oct 2002
    Location
    Milan, Italy, Europe
    Posts
    188

    Re: Masked password + MD5 encryption

    For example, it could be:
    Code:
    Module Module1
    
        Private _cyphredPassword As String = String.Empty
        'correct pwd is "sian" (without the quotes)
        Private Const correctPwd As String = "5OoLtL2yrc0/2nBmVfY5YQ=="
        Sub Main()
    
            Dim sb As New System.Text.StringBuilder
            sb.AppendLine()
    
            If LogIn() Then
    
                sb.AppendLine("You succesfully logged in")
    
            Else
                sb.AppendLine("Invalid userName or Password")
            End If
    
            sb.AppendLine("Press any key to quit")
            Console.WriteLine(sb.ToString)
            Console.ReadKey()
        End Sub
    
    
        Private Function LogIn() As Boolean
            Dim ret As Boolean = False
    
            'A log in system to prevent unwanted users from acsessing the system
            Console.Write("Username: ")
            Dim username As String = Console.ReadLine.ToLower
            If username = "sian" Then
                ret = loginPassword()
                'If the username is correct it goes on to the main screen.
            Else
                'If the username is wrong it loops back into the log in
                Console.Clear()
                ret = LogIn()
            End If
            Return ret
        End Function
    
        'If the password is correct it goes on to ask for the password
        Private Function loginPassword() As Boolean
            Dim ret As Boolean
            Dim plainPassowrd As String = String.Empty
            Console.Write("Password (press enter when you are done) : ")
            Do
                Dim keyPressed As ConsoleKeyInfo = Console.ReadKey(True)
                Select Case keyPressed.Key
                    Case ConsoleKey.A To ConsoleKey.Z
                        Console.Write("*")
                        plainPassowrd += keyPressed.KeyChar
                    Case ConsoleKey.Enter
    
                        Exit Do
                End Select
    
    
    
            Loop
            If Not String.IsNullOrEmpty(plainPassowrd.Trim) Then
                _cyphredPassword = EncryptPwd(plainPassowrd)
                If _cyphredPassword.Equals(correctPwd, System.StringComparison.Ordinal) Then
                    ret = True
                End If
            End If
    
            Return ret
        End Function
    
        Private Function EncryptPwd(plainPassowrd As String) As String
            '
            'this routine is from: http://www(dot)a1vbcode(dot)com/vbtip-149(dot)asp
            '
            '(substitute "(dot)" with "." if you want to go there. I posted as I try to give credits to those who deserve)
            '
            'Create an encoding object to ensure the encoding standard for the source text
            Dim Ue As New System.Text.UnicodeEncoding()
            'Retrieve a byte array based on the source text
            Dim ByteSourceText() As Byte = Ue.GetBytes(plainPassowrd)
            'Instantiate an MD5 Provider object
            Dim Md5 As New System.Security.Cryptography.MD5CryptoServiceProvider()
            'Compute the hash value from the source
            Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
            'And convert it to String format for return
            Return Convert.ToBase64String(ByteHash)
    
        End Function
    
    End Module
    Special thanks to some wonderful people,
    such as Lothar the Great Haensler, Aaron Young,
    dr_Michael, Chris Eastwood, TheOnlyOne ClearCode....

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.