Advertisement
sciexie

log in

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