Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports MySql.Data.MySqlClient
- Imports System.Security.Cryptography
- Imports System.Text
- Public Class FrmLogin
- Public connDB As New MySqlConnection
- Public comDB As New MySqlCommand
- Public rdDB As MySqlDataReader
- Public myError As MySqlError
- Public SQL As String
- Sub conectDB()
- Dim strServer As String = "localhost"
- Dim strDbase As String = "testdb"
- Dim strUser As String = "root"
- Dim strPass As String = ""
- If connDB.State <> ConnectionState.Open Then connDB.ConnectionString = "server=" & strServer.Trim & ";database=" & strDbase.Trim & ";user=" & strUser.Trim & ";password=" & strPass
- If connDB.State <> ConnectionState.Open Then connDB.Open()
- End Sub
- Sub closeDB()
- If connDB.State <> ConnectionState.Closed Then connDB.Close()
- End Sub
- Sub initCMD()
- With comDB
- .Connection = connDB
- .CommandType = CommandType.Text
- .CommandTimeout = 280000
- End With
- End Sub
- Function getMD5Hash(ByVal strToHash As String) As String
- Dim md5Obj As New MD5CryptoServiceProvider()
- Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)
- bytesToHash = md5Obj.ComputeHash(bytesToHash)
- Dim strResult As String = ""
- Dim b As Byte
- For Each b In bytesToHash
- strResult += b.ToString("x2")
- Next
- Return strResult
- End Function
- Private Sub FrmLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- txtPassword.Text = ""
- txtUsername.Text = ""
- txtUsername.Select()
- End Sub
- Private Function ValidasiEntry() As Boolean
- If Me.txtUsername.Text.Trim = "" Or
- Me.txtPassword.Text.Trim = "" Then
- MsgBox("Username & Password Tidak Boleh Kosong!", MsgBoxStyle.Exclamation, "Error")
- Return True
- End If
- End Function
- Private Sub CekUser()
- Try
- SQL = "SELECT * from users " &
- "WHERE status = '1' " &
- "AND username ='" & Me.txtUsername.Text & "' " &
- "AND password ='" & getMD5Hash(txtPassword.Text) & "'"
- With comDB
- .CommandText = SQL
- .ExecuteNonQuery()
- End With
- rdDB = comDB.ExecuteReader
- rdDB.Read()
- If rdDB.HasRows = True Then
- Me.Hide()
- Form1.Show()
- Else
- MsgBox("Username and or Password not found!", MsgBoxStyle.Exclamation, "Information")
- txtUsername.Text = ""
- txtPassword.Text = ""
- txtUsername.Select()
- End If
- rdDB.Close()
- Catch ex As Exception
- MsgBox(ex.ToString)
- End Try
- End Sub
- Private Sub LoadData(ByVal sender As Object, ByVal e As KeyEventArgs) Handles txtUsername.KeyDown, txtPassword.KeyDown
- If e.KeyCode = Keys.Enter Then
- ProcessTabKey(True)
- End If
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- If ValidasiEntry() = True Then
- txtUsername.Select()
- Exit Sub
- End If
- Call conectDB()
- Call initCMD()
- Call CekUser()
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- Me.Close()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement