• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Signing into your application with MySQL / VB

Archenemy

Enthusiast
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.

Code:
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 = _
                "ConnectionString"

            DevBytesToH = DevShaOneObj.ComputeHash(DevBytesToH)

            Dim DevHashResult As String = ""

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

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

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

        End Sub
    End Class

End Class
 
Top