View Full Version : Signing into your application with MySQL / VB

08-08-2013, 05:32 AM
In this case, you would take information given by the user and DevUsername and DevPassword would be set to those values. DevPassword will then be turned to a SHA1 value. It will then check if the Username and SHA1 value matches any user in the database and if it does, DevLoggedIn is assigned a true value if not, a false one. You can decide what happens if DevLoggedIn = True or False from that point on.

Imports MySql.Data.MySqlClient
Public Class Devossoft

Public Shared DevLoggedIn As Boolean

Public Shared DevUsername As String
Public Shared DevPassword As String

Public Class Authenticate
Public Shared Sub TryLogin()
Dim DevConnection As New MySqlConnection
Dim DevCommand As New MySqlCommand
Dim DevDataReader As MySqlDataReader
Dim DevShaOneObj As New Security.Cryptography.SHA1CryptoServiceProvider
Dim DevBytesToH() As Byte = System.Text.Encoding.ASCII.GetBytes(DevPassword)
DevConnection.ConnectionString = _

DevBytesToH = DevShaOneObj.ComputeHash(DevBytesToH)

Dim DevHashResult As String = ""

For Each b As Byte In DevBytesToH
DevHashResult += b.ToString("x2")

DevCommand.Connection = DevConnection
DevCommand.CommandText = _
"SELECT * FROM xxx WHERE username = '" + DevUsername + "' AND password = '" + DevHashResult + "'"
DevDataReader = DevCommand.ExecuteReader

If DevDataReader.HasRows Then
DevLoggedIn = True
DevLoggedIn = False
MsgBox("The information you supplied is incorrect. Please try again.", MsgBoxStyle.Information, "Devossoft")
End If

End Sub
End Class

End Class

08-08-2013, 05:35 AM
Ah, this may help a few people! Thanks for sharing with us!