Advertisement
ElliottE4

Untitled

Apr 7th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.25 KB | None | 0 0
  1. Imports System.IO 'imports the system io library
  2. Imports System.Text.RegularExpressions
  3. Imports System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel
  4.  
  5. Public Class Login
  6.     Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  7.  
  8.         'when the form loads, the getfilelocation subroutine runs
  9.         getfilelocation() 'finds the location of the staff file, and creates it if it doesn't exist
  10.         txt_Username.Clear() 'clears the username textbox
  11.         txt_Password.Clear() 'clears the password textbox
  12.  
  13.     End Sub
  14.  
  15.     Private Sub btn_Login_Click(sender As Object, e As EventArgs) Handles btn_Login.Click
  16.  
  17.         Dim validation As New Validation 'allows the use of the validation class
  18.  
  19.         Dim passwordMatch As Boolean = False 'creates a varaible that will be used to check if the password is incorrect
  20.         Dim usernameMatch As Boolean = False 'creates a varaible that will be used to check if the username is incorrect
  21.  
  22.         Dim username As String 'creates a username variable
  23.         Dim password As String 'creates a password variable
  24.  
  25.         Dim currentUser As String 'creates a variable to store the current user information
  26.         Dim loginFields() As String 'creates a variable to store the information input into the login fields
  27.  
  28.         Dim match As Boolean = False 'creates match variable to check if username and password match later on
  29.         username = UCase(txt_Username.Text) 'sets the username variable to an uppercase version of the username in textbox
  30.         password = txt_Password.Text 'sets the password variable to the data in password textbox
  31.  
  32.         'check if username and password textboxes are empty (presence check):
  33.         If Validation.presenceCheck(username) = False Or Validation.presenceCheck(password) = False Then
  34.  
  35.             MsgBox("Please input data into both textboxes") 'shows message to ask user to input data into texboxes
  36.             txt_Username.Clear() 'clears username textbox
  37.             txt_Password.Clear() 'clears password textbox
  38.  
  39.         End If
  40.  
  41.         Dim sr As New StreamReader(staffFile) 'opens streamread, to allow the staff file to be read
  42.         While sr.Peek >= 0 'while the file isn't at the end line
  43.  
  44.             currentUser = sr.ReadLine 'reads the the first line of the file, then each loop reads the next line
  45.             loginFields = currentUser.Split(",") 'the line is split into different sections by splitting at every comma
  46.  
  47.  
  48.             'if the username matches the first field in the staff text file with all caps, and the password matches the second field in the staff text file, then:
  49.             If username = UCase(Decryption(loginFields(1))) AndAlso password = Decryption(loginFields(2)) Then
  50.  
  51.                 'match has been found:
  52.                 Security = Decryption(loginFields(5)) 'sets the access level to the lowest to allow the next form to be accessed
  53.  
  54.                 usernameMatch = True
  55.                 passwordMatch = True
  56.                 match = True 'checks if the input data matches any data in the textfile
  57.                 Exit While 'ends the loop as a match has been found
  58.  
  59.  
  60.             End If
  61.  
  62.             If username = UCase(Decryption(loginFields(1))) Then
  63.  
  64.                 usernameMatch = True 'username is correct
  65.  
  66.             End If
  67.  
  68.             If password = UCase(Decryption(loginFields(2))) Then
  69.  
  70.                 passwordMatch = True 'password is correct
  71.  
  72.             End If
  73.  
  74.         End While
  75.  
  76.         If passwordMatch = False Then
  77.  
  78.             MsgBox("Incorrect password, please try again")
  79.             txt_Password.Clear()
  80.  
  81.         End If
  82.  
  83.         If usernameMatch = False Then
  84.  
  85.             MsgBox("Incorrect username, please try again")
  86.             txt_Username.Clear()
  87.  
  88.         End If
  89.  
  90.         sr.Close() 'closes streamreader to avoid data loss
  91.  
  92.         If match = True Then 'if a match has been found:
  93.  
  94.             Me.Visible = False
  95.             LibraryMenu.Visible = True
  96.  
  97.         End If
  98.  
  99.     End Sub
  100.  
  101.     Private Sub pbx_ExitButton_Click(sender As Object, e As EventArgs) Handles pbx_ExitButton.Click
  102.  
  103.         If MsgBox("Are you sure you want to quit the program?", vbYesNo) = vbYes Then
  104.  
  105.             'when the exit button is clicked, exit the program if yes is selected
  106.             Application.Exit() 'closes the program
  107.  
  108.         End If
  109.  
  110.     End Sub
  111.  
  112.     Private Sub btn_Forgotten_Click(sender As Object, e As EventArgs) Handles btn_Forgotten.Click
  113.  
  114.         Me.Visible = False 'hides the login form
  115.         ForgottenPassword.Visible = True 'shows the forgotten password form
  116.  
  117.     End Sub
  118.  
  119.     Private Sub btn_Help_Click(sender As Object, e As EventArgs) Handles btn_Help.Click
  120.  
  121.         Help.txt_help.Text = "This is the login form. Input your username into the username textbox, and input your password into the password textbox," _
  122.             & " Then click the login button. If you aren't redirected to the menu form, then either your username or password is incorrect. If you have" _
  123.             & " forgotten your password, then you can click on the 'forgotten password' button to be redirected to that form. If you click the cross button" _
  124.             & " in the top right of the form, you will exit the program."
  125.  
  126.         Help.Show()
  127.  
  128.     End Sub
  129. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement