Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.SqlClient
- Imports System.Data.Odbc
- Public Class log_in
- Dim userFound As Boolean = False
- Dim userType As String
- Dim secQuestion As String
- Dim Fullname As String
- Dim rightanswer As String
- Dim usrname As String
- Private Sub txtUser_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUser.KeyDown
- If e.KeyCode = 13 Then txtPass.Focus()
- End Sub
- Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- frmRegister.ShowDialog()
- End Sub
- Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
- connectMe()
- Dim conn As New OdbcConnection(constring)
- Dim cmd As New OdbcCommand
- Dim dt As New DataTable
- Dim sql As String = " select username, password, designation, sQuestion, Fullname from users where username=? and password=?"
- cmd = New OdbcCommand(sql, conn)
- cmd.Parameters.AddWithValue("@username", txtUser.Text.ToUpper.Trim)
- cmd.Parameters.AddWithValue("@password", txtPass.Text)
- windows.userName = txtUser.Text
- If conn.State = ConnectionState.Closed Then
- conn.Open()
- Dim sqlReader As OdbcDataReader = cmd.ExecuteReader()
- While sqlReader.Read
- userFound = True
- userType = sqlReader("Designation").ToString
- Fullname = sqlReader("Fullname").ToString
- End While
- If userFound = True Then
- If userType = "ADMIN" Then
- Me.userName = txtUser.Text
- FrmMain.pbUsertype.Image = My.Resources.adminGif
- LOADING.Show()
- Me.Close()
- ElseIf userType = "FACULTY" Or userType = "PROFESSOR" Then
- usrname = txtUser.Text
- frm_main_Faculty.pbUsertype.Image = My.Resources.adminaaa
- fac_Loading.Show()
- Me.Hide()
- frm_main_Faculty.lblWelcome.Text = "Welcome" + vbCrLf + Fullname.ToString + vbCrLf + "( " + userType.ToString + " )"
- ElseIf userType = "REGISTRAR" Then
- usrname = txtUser.Text
- loading_registrar.Show()
- Me.Hide()
- frmMain_Reg.lblWelcome.Text = "Welcome" + vbCrLf + Fullname.ToString + vbCrLf + "( " + userType.ToString + " )"
- End If
- FrmMain.lblWelcome.Text = "Welcome" + vbCrLf + Fullname.ToString + vbCrLf + "( " + userType.ToString + " )"
- Else
- MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
- End If
- Else
- conn.Close()
- End If
- End Sub
- Private Sub lnkFPass_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkFPass.LinkClicked
- userFound = False
- connectMe()
- Dim conn As New OdbcConnection(constring)
- Dim cmd As OdbcCommand
- Dim dt As New DataTable
- Dim sql As String = " select sQuestion,Answer from users where username='" & txtUser.Text.ToUpper.Trim & "'"
- cmd = New OdbcCommand(sql, conn)
- If conn.State = ConnectionState.Closed Then
- conn.Open()
- Dim sqlReader As OdbcDataReader = cmd.ExecuteReader()
- While sqlReader.Read
- userFound = True
- secQuestion = sqlReader("sQuestion").ToString
- rightanswer = sqlReader("Answer").ToString
- End While
- If userFound = True Then
- Dim Answer As String
- Answer = InputBox(secQuestion, "Secret Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
- txtPass.Focus()
- If Answer = rightanswer Then
- windows.userName = txtUser.Text
- windows.Show()
- Else
- MsgBox("Oops, please enter the correct answer", MsgBoxStyle.OkOnly, "WARNING")
- End If
- Else
- MsgBox("Sorry, username not found", MsgBoxStyle.OkOnly, "Invalid Login")
- txtUser.Focus()
- End If
- Else
- conn.Close()
- End If
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Me.Close()
- End Sub
- Public Property userName() As String
- Get
- Return usrname
- End Get
- Set(ByVal value As String)
- usrname = value
- End Set
- End Property
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement