Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports MySql.Data.MySqlClient
- Public Class Connection
- Private connection As MySqlConnection = New MySqlConnection
- Private adapter As New MySqlDataAdapter
- Private query As String
- Private command As New MySqlCommand
- Private user As String
- Private password(2) As String
- Public Whisper As Boolean = False
- Public Function SetConnectionData(ByVal ip As String, ByVal username As String, ByVal pw As String, ByVal database As String)
- connection.ConnectionString = "server=" & ip & ";" & "user id=" & username & ";" & "password=" & pw & ";" & "database=" & database
- End Function
- Public Function InitializeLogin(ByVal usernametextbox As TextBox, ByVal pwtextbox As TextBox)
- user = MD5StringHash(usernametextbox.Text)
- password(0) = MD5StringHash(pwtextbox.Text)
- Try
- connection.Open() ' Try to connect
- Catch myerror As MySqlException
- MsgBox("No Connection to the Database!", MsgBoxStyle.Critical, "Fatal Error!") ' If the person fails to connect
- End Try
- query = "SELECT * FROM Laff WHERE puname ='" + Replace(user, " ", "") + "' AND plass='" & Replace(password(0), " ", "") & "'"
- command.Connection = connection
- command.CommandText = query
- adapter.SelectCommand = command
- Dim _myData As MySqlDataReader
- _myData = command.ExecuteReader() ' Start of the query
- If _myData.HasRows Then ' If the query contains rows ( the password and username were right )
- connection.Close()
- Whisper = True
- Else ' If username / password are wrong
- MsgBox("Error! Wrong username/password!")
- Whisper = False
- End If
- End Function
- Public Function InitializeRegister(ByVal usernametextbox As TextBox, ByVal pw1textbox As TextBox, ByVal pw2textbox As TextBox)
- user = MD5StringHash(usernametextbox.Text)
- password(0) = MD5StringHash(pw1textbox.Text)
- password(1) = MD5StringHash(pw2textbox.Text)
- If password(0) = password(1) Then ' If the textboxes passwords are the same
- Try
- connection.Open() ' Open the connection
- Catch myerror As MySqlException
- MsgBox("No connection to the database!", MsgBoxStyle.Critical, "Fatal Error!")
- End Try
- Dim myAdapter As New MySqlDataAdapter
- Dim SQLAbfrage As String = "SELECT * FROM users WHERE username='" + user + "'" ' Query if the user already exists
- Dim _tmp_myCommand As New MySqlCommand
- _tmp_myCommand.Connection = connection
- _tmp_myCommand.CommandText = SQLAbfrage
- myAdapter.SelectCommand = _tmp_myCommand
- Dim myData As MySqlDataReader
- myData = _tmp_myCommand.ExecuteReader() ' Start query
- If myData.HasRows = 0 Then ' If the username already exists it won't begin with the registration
- connection.Close()
- connection.Open()
- Dim registerfinal As New MySqlDataAdapter
- _tmp_myCommand.CommandText = "INSERT INTO users(username, password)" _
- & "VALUES('" & user & "','" & password(0) & "')"
- _tmp_myCommand.ExecuteNonQuery() ' Start SQL query and insert
- MsgBox("The account with the name: " & usernametextbox.Text & " was created sucessfully!", MsgBoxStyle.Information, "Yep =)")
- connection.Close()
- Else
- MsgBox("This username does already exist", MsgBoxStyle.Information, "Sorry")
- End If
- Else
- MsgBox("The passwords did not match!", MsgBoxStyle.Critical, "Error!")
- End If
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement