Advertisement
Guest User

how to code a 3 times attempt log in

a guest
Oct 12th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.84 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2. Imports System.IO
  3.  
  4.  
  5. Public Class frmlogin
  6.  
  7.     Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
  8.         End
  9.     End Sub
  10.  
  11.     Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
  12.  
  13.         On Error GoTo err
  14.         Dim conn As New MySqlConnection
  15.         Dim areader As MySqlDataReader
  16.         Dim cmd As New MySqlCommand
  17.  
  18.         Dim loginat As Integer = 0
  19.  
  20.         conn.ConnectionString = "Server = localhost; Database = data; User ID = root; Password = "
  21.         cmd.Connection = conn
  22.         conn.Open()
  23.  
  24.  
  25.         cmd.CommandText = "select * from admin where username ='" & txtuser.Text & "'"
  26.         cmd.Connection = conn
  27.         areader = cmd.ExecuteReader()
  28.  
  29.         Dim validlogin As Boolean
  30.         validlogin = False
  31.  
  32.  
  33.         If areader.HasRows = True Then
  34.             areader.Read()
  35.             If areader.Item("password") = txtpass.Text Then
  36.                 validlogin = True
  37.  
  38.  
  39.                 Dim fn, position, user_type As String
  40.                 Dim image As String
  41.                 fn = areader.Item("FirstName")
  42.                 position = areader.Item("position")
  43.                 user_type = areader.Item("type")
  44.  
  45.  
  46.                 If txtuser.Text = "" And txtpass.Text = "" Then
  47.                     MsgBox("Please fill in all boxes")
  48.  
  49.                 ElseIf user_type = "Main Admin" Then
  50.  
  51.                     MsgBox("Welcome " & fn & " you login as Main Administrator ", MsgBoxStyle.Information, "Access Granted")
  52.  
  53.                     loginat = 0
  54.  
  55.                     frmadmain.Show()
  56.                     Me.Hide()
  57.  
  58.  
  59.                     frmadmain.lblname.Visible = True
  60.                     frmadmain.lblname.Text = fn
  61.                     frmadmain.txtUser.Text = user_type
  62.                     txtuser.Text = ""
  63.                     txtpass.Text = ""
  64.  
  65.                 Else
  66.  
  67.                     MsgBox("Welcome " & fn & " you login as " & position & " ", MsgBoxStyle.Information, "Access Granted")
  68.  
  69.                     loginat = 0
  70.  
  71.                     frmmain.Show()
  72.                     Me.Hide()
  73.  
  74.                     frmadmain.lblname.Visible = True
  75.                     frmadmain.lblname.Text = fn
  76.                     frmadmain.txtUser.Text = user_type
  77.                     txtuser.Text = ""
  78.                     txtpass.Text = ""
  79.  
  80.  
  81.                 End If
  82.  
  83.  
  84.             Else
  85.                 txtuser.Text = ""
  86.                 txtpass.Text = ""
  87.                 txtuser.Focus()
  88.                 txtpass.Focus()
  89.                 MsgBox("Password not match", MsgBoxStyle.Exclamation, "Access Denied")
  90.                 loginat += 1
  91.  
  92.             End If
  93.         Else
  94.             txtuser.Text = ""
  95.             txtpass.Text = ""
  96.             txtuser.Focus()
  97.             txtpass.Focus()
  98.             MsgBox("Incorrect username", MsgBoxStyle.Exclamation, "Access Denied")
  99.             loginat += 1
  100.  
  101.         End If
  102.  
  103.         lbllog.Text = loginat
  104.  
  105.         If loginat = 2 Then
  106.             MsgBox("Last change to login, or the system will close!", MsgBoxStyle.Exclamation, "Caution")
  107.         ElseIf loginat = 3 Then
  108.             MsgBox("Sorry the system will now close!", MsgBoxStyle.Exclamation, "Caution")
  109.             Me.Close()
  110.  
  111.         End If
  112.  
  113.  
  114.  
  115.         If validlogin = True Then
  116.  
  117.             Dim alreadylogin = True
  118.             Dim userlogin = areader.Item("username")
  119.             txtuser.Text = ""
  120.             txtpass.Text = ""
  121.  
  122.             areader.Close()
  123.  
  124.             ' you can add another code or call function in this section
  125.             ''Me.Dispose()
  126.  
  127.         Else
  128.             areader.Close()
  129.             txtpass.Text = ""
  130.             MsgBox(Err, MsgBoxStyle.Information)
  131.  
  132.         End If
  133.  
  134.  
  135.        
  136.  
  137.  
  138.         Exit Sub
  139. err:
  140.  
  141.     End Sub
  142. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement