Option Explicit On
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents txtUsername As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Dim mySQL As ADODB.Connection
Public Username As String
Public perms As String
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mySQL = New ADODB.Connection()
mySQL.ConnectionString = ("Provider=MSDASQL;Driver={MySQL ODBC 3.51 Driver};Database=workorder;Server=IP;UID=user;PWD=password;OPTION=147458")
mySQL.Open()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Response.Redirect("index.htm")
End Sub
Public Function UserCheck(ByVal strUserName As String, ByVal strPassword As String) As Boolean
Dim rs As New ADODB.Recordset()
rs.Open("SELECT username, password FROM users WHERE username = '" & strUserName & "'", mySQL, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
If Not rs.EOF Then
If rs.Fields("password") Is strPassword Then
rs.Close()
rs = Nothing
UserCheck = True
Exit Function
Else
rs.Close()
rs = Nothing
UserCheck = False
Exit Function
End If
Else
rs.Close()
rs = Nothing
UserCheck = False
Exit Function
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mrs As ADODB.Recordset
Dim permQuery As String
Dim writeQuery As String
Username = txtUsername.Text
permQuery = "SELECT permissions FROM users WHERE username = '" & Username & "'"
mrs = New ADODB.Recordset()
mrs.Open(permQuery, mySQL, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
If Not mrs.EOF Then
perms = mrs.Fields("permissions").Value
mrs.Close()
mrs = Nothing
End If
writeQuery = "INSERT INTO verify(username, permissions) VALUES ('" & Username & "', '" & perms & "')"
If UserCheck(txtUsername.Text, txtPassword.Text) = True Then
mySQL.Execute(writeQuery)
mySQL.Close()
mySQL = Nothing
Response.Redirect("menu.aspx")
Else
Response.Redirect("Login.aspx")
End If
End Sub
End Class