Here is the login.form:
Imports MySql.Data.MySqlClient
Public Class Login
Dim server As String = "Server=localhost;Database=escola_musica;Uid=root;Pwd=;"
'Dim server As String = "Server=localhost;Database=esola_musica;Uid=root;Pwd=;"
Dim con As New MySqlConnection
Dim da As New MySqlDataAdapter
Dim sql As String
Dim cmd As New MySqlCommand(sql, con)
Dim dr As MySqlDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Ligação �* BD
con.ConnectionString = server
Try
If con.State = ConnectionState.Closed Then
con.Open()
Else
con.Close()
MsgBox("Ligação falhada!!")
End If
Catch erro As Exception
MsgBox(erro.ToString)
End Try
'Log in
sql = "SELECT * FROM admin WHERE username = '" & user_box.Text & "' AND pass = '" & pass_box.Text & "'"
With cmd
.CommandText = sql
.CommandType = CommandType.Text
.Connection = con
End With
dr = cmd.ExecuteReader
If dr.Read Then
If (dr("username") <> user_box.Text) Or (dr("pass") <> pass_box.Text) Then
MsgBox("Utilizador ou pass invalida")
Exit Sub
Else
MsgBox("correcto!")
Principal.Show()
con.Close()
Me.Close()
Exit Sub
End If
End If
If Trim(user_box.Text) <> "" And Trim(pass_box.Text) <> "" Then
Principal.Show()
Me.Close()
Else
MsgBox("erro! -.-' ")
End If
End Sub
Private Sub reg_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reg_button.Click
Admin_Reg.Show()
Me.Close()
End Sub
End Class
Here is the admin_reg.form:
Imports MySql.Data.MySqlClient
Public Class Admin_Reg
Dim server As String = "Server=localhost;Database=escola_musica;Uid=root;Pwd=;"
'Dim server As String = "Server=localhost;Database=esola_musica;Uid=root;Pwd=;"
Dim con As New MySqlConnection
Dim sql_sel As String = "SELECT (username, pass) FROM admin WHERE username = '" & user_box.Text & "' AND pass = '" & pass_box.Text & "'"
Dim dr As MySqlDataReader
Dim da As New MySqlDataAdapter
Dim cmd As New MySqlCommand
Dim sql_ins As String = "INSERT INTO admin (username, pass)VALUES ('" & user_box.Text & "','" & pass_box.Text & "')"
Private Sub reg_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reg_button.Click
'Ligação �* BD
con.ConnectionString = server
Try
If con.State = ConnectionState.Closed Then
con.Open()
Else
con.Close()
MsgBox("Ligação falhada!!")
End If
Catch erro As Exception
MsgBox(erro.ToString)
End Try
cmd.Connection = con
cmd.CommandText = sql_ins
'start query
da.SelectCommand = cmd
dr = cmd.ExecuteReader()
'see if user exits.
If dr.HasRows = 0 Then
MsgBox("Invalid Authkey")
Else
MsgBox("Authentication Key accepted!")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Login.Show()
Me.Close()
End Sub
End Class
Can someone help me?
Thank you


Sign In
Create Account

Back to top









