Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Strict On
- Imports System.IO
- Public Class Form1
- Private Function StringtoMD5(ByRef Content As String) As String
- Dim M5 As New System.Security.Cryptography.MD5CryptoServiceProvider
- Dim ByteString() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
- ByteString = M5.ComputeHash(ByteString)
- Dim FinalString As String = Nothing
- For Each bt As Byte In ByteString
- FinalString &= bt.ToString("x2")
- Next
- Return FinalString.ToUpper()
- End Function
- Private Function createUser(ByVal user As String, ByVal pass As String) As String ' Declares user and pass as strings
- 'check to see if the MD5 has value of user exsists as a text file
- If File.Exists(StringtoMD5(user) & ".txt") = False Then
- Try
- ' write MD5 hash values of user and pass to a file names <user>.txt
- My.Computer.FileSystem.WriteAllText(StringtoMD5(user) & ".txt", StringtoMD5(user) & Chr(32) & StringtoMD5(pass), False)
- File.SetAttributes(StringtoMD5(user) & ".txt", FileAttributes.Hidden)
- ' If it works
- MsgBox("It worked", MsgBoxStyle.Information)
- Catch ex As Exception
- ' if it fails to write, then show an error message
- MsgBox("Something had went wrong" & ex.Message, MsgBoxStyle.Information, "Error")
- End Try
- Else
- ' username has already been created
- MsgBox("Username has already been taken")
- End If
- ' return values
- Return user
- Return pass
- End Function
- Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
- Try
- 'check to see if the MD5 hashed value of user.txt and pass.txt are equal to the hash values inside
- 'the file. We find the file by using IO.File.ReadAllText to find the MD5 hashed named file of <user>.txt
- 'int real situations, you would replace the IO.File.ReadAllText with a connection to your database/server/website
- If StringtoMD5(UsernameTextBox.Text) & Chr(32) & StringtoMD5(PasswordTextBox.Text) = IO.File.ReadAllText(StringtoMD5(UsernameTextBox.Text) & ".txt") Then
- ' if is works, let the user login
- ' in this area, you can give a message to the database/server/website to allow the user to connect
- MsgBox("You have entered the correct credentials", MsgBoxStyle.Information)
- Else
- ' if credentials did not match
- MsgBox("You have NOT entered the correct credentials")
- End If
- Catch ex As Exception
- 'If user never registered or something bizarrly happens
- MsgBox(ex.Message, MsgBoxStyle.Information, "Error")
- Exit Sub
- End Try
- End Sub
- Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- createUser(UsernameTextBox.Text, PasswordTextBox.Text)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement