Advertisement
sciexie

log in

Mar 14th, 2018
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. Imports System.Data.SqlClient
  2. Imports System.Data.Odbc
  3.  
  4. Public Class log_in
  5.  
  6. Dim userFound As Boolean = False
  7. Dim userType As String
  8. Dim secQuestion As String
  9. Dim Fullname As String
  10. Dim rightanswer As String
  11. Dim usrname As String
  12.  
  13.  
  14.  
  15.  
  16.  
  17. Private Sub txtUser_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUser.KeyDown
  18.  
  19. If e.KeyCode = 13 Then txtPass.Focus()
  20.  
  21. End Sub
  22.  
  23. Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  24. frmRegister.ShowDialog()
  25. End Sub
  26.  
  27. Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
  28.  
  29.  
  30. connectMe()
  31. Dim conn As New OdbcConnection(constring)
  32. Dim cmd As New OdbcCommand
  33. Dim dt As New DataTable
  34. Dim sql As String = " select username, password, designation, sQuestion, Fullname from users where username=? and password=?"
  35. cmd = New OdbcCommand(sql, conn)
  36.  
  37. cmd.Parameters.AddWithValue("@username", txtUser.Text.ToUpper.Trim)
  38. cmd.Parameters.AddWithValue("@password", txtPass.Text)
  39.  
  40.  
  41. windows.userName = txtUser.Text
  42. If conn.State = ConnectionState.Closed Then
  43. conn.Open()
  44.  
  45. Dim sqlReader As OdbcDataReader = cmd.ExecuteReader()
  46.  
  47. While sqlReader.Read
  48. userFound = True
  49. userType = sqlReader("Designation").ToString
  50. Fullname = sqlReader("Fullname").ToString
  51.  
  52. End While
  53.  
  54.  
  55. If userFound = True Then
  56. If userType = "ADMIN" Then
  57. Me.userName = txtUser.Text
  58. FrmMain.pbUsertype.Image = My.Resources.adminGif
  59. LOADING.Show()
  60. Me.Close()
  61. ElseIf userType = "FACULTY" Or userType = "PROFESSOR" Then
  62. usrname = txtUser.Text
  63. frm_main_Faculty.pbUsertype.Image = My.Resources.adminaaa
  64. fac_Loading.Show()
  65. Me.Hide()
  66. frm_main_Faculty.lblWelcome.Text = "Welcome" + vbCrLf + Fullname.ToString + vbCrLf + "( " + userType.ToString + " )"
  67.  
  68.  
  69. ElseIf userType = "REGISTRAR" Then
  70. usrname = txtUser.Text
  71. loading_registrar.Show()
  72. Me.Hide()
  73. frmMain_Reg.lblWelcome.Text = "Welcome" + vbCrLf + Fullname.ToString + vbCrLf + "( " + userType.ToString + " )"
  74.  
  75.  
  76. End If
  77. FrmMain.lblWelcome.Text = "Welcome" + vbCrLf + Fullname.ToString + vbCrLf + "( " + userType.ToString + " )"
  78.  
  79.  
  80.  
  81. Else
  82.  
  83. MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
  84. End If
  85. Else
  86. conn.Close()
  87. End If
  88. End Sub
  89.  
  90. Private Sub lnkFPass_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkFPass.LinkClicked
  91. userFound = False
  92.  
  93.  
  94.  
  95. connectMe()
  96. Dim conn As New OdbcConnection(constring)
  97. Dim cmd As OdbcCommand
  98. Dim dt As New DataTable
  99. Dim sql As String = " select sQuestion,Answer from users where username='" & txtUser.Text.ToUpper.Trim & "'"
  100. cmd = New OdbcCommand(sql, conn)
  101.  
  102.  
  103.  
  104. If conn.State = ConnectionState.Closed Then
  105. conn.Open()
  106.  
  107. Dim sqlReader As OdbcDataReader = cmd.ExecuteReader()
  108. While sqlReader.Read
  109. userFound = True
  110. secQuestion = sqlReader("sQuestion").ToString
  111. rightanswer = sqlReader("Answer").ToString
  112. End While
  113. If userFound = True Then
  114.  
  115. Dim Answer As String
  116.  
  117.  
  118. Answer = InputBox(secQuestion, "Secret Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
  119. txtPass.Focus()
  120.  
  121. If Answer = rightanswer Then
  122. windows.userName = txtUser.Text
  123.  
  124.  
  125. windows.Show()
  126. Else
  127. MsgBox("Oops, please enter the correct answer", MsgBoxStyle.OkOnly, "WARNING")
  128.  
  129.  
  130.  
  131. End If
  132.  
  133.  
  134. Else
  135. MsgBox("Sorry, username not found", MsgBoxStyle.OkOnly, "Invalid Login")
  136. txtUser.Focus()
  137.  
  138. End If
  139.  
  140. Else
  141. conn.Close()
  142. End If
  143.  
  144.  
  145.  
  146. End Sub
  147.  
  148. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  149. Me.Close()
  150.  
  151. End Sub
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. Public Property userName() As String
  163. Get
  164. Return usrname
  165.  
  166. End Get
  167. Set(ByVal value As String)
  168. usrname = value
  169. End Set
  170. End Property
  171.  
  172. Private Sub txtPass_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPass.KeyDown
  173.  
  174. If e.KeyCode = 13 Then btnLogin.Focus()
  175.  
  176.  
  177. End Sub
  178.  
  179.  
  180.  
  181.  
  182.  
  183. Private Sub txtPass_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPass.TextChanged
  184.  
  185.  
  186.  
  187.  
  188. End Sub
  189.  
  190.  
  191. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement