Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO 'imports the system io library
- Imports System.Text.RegularExpressions
- Imports System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel
- Public Class Login
- Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- 'when the form loads, the getfilelocation subroutine runs
- getfilelocation() 'finds the location of the staff file, and creates it if it doesn't exist
- txt_Username.Clear() 'clears the username textbox
- txt_Password.Clear() 'clears the password textbox
- End Sub
- Private Sub btn_Login_Click(sender As Object, e As EventArgs) Handles btn_Login.Click
- Dim validation As New Validation 'allows the use of the validation class
- Dim passwordMatch As Boolean = False 'creates a varaible that will be used to check if the password is incorrect
- Dim usernameMatch As Boolean = False 'creates a varaible that will be used to check if the username is incorrect
- Dim username As String 'creates a username variable
- Dim password As String 'creates a password variable
- Dim currentUser As String 'creates a variable to store the current user information
- Dim loginFields() As String 'creates a variable to store the information input into the login fields
- Dim match As Boolean = False 'creates match variable to check if username and password match later on
- username = UCase(txt_Username.Text) 'sets the username variable to an uppercase version of the username in textbox
- password = txt_Password.Text 'sets the password variable to the data in password textbox
- 'check if username and password textboxes are empty (presence check):
- If Validation.presenceCheck(username) = False Or Validation.presenceCheck(password) = False Then
- MsgBox("Please input data into both textboxes") 'shows message to ask user to input data into texboxes
- txt_Username.Clear() 'clears username textbox
- txt_Password.Clear() 'clears password textbox
- End If
- Dim sr As New StreamReader(staffFile) 'opens streamread, to allow the staff file to be read
- While sr.Peek >= 0 'while the file isn't at the end line
- currentUser = sr.ReadLine 'reads the the first line of the file, then each loop reads the next line
- loginFields = currentUser.Split(",") 'the line is split into different sections by splitting at every comma
- '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:
- If username = UCase(Decryption(loginFields(1))) AndAlso password = Decryption(loginFields(2)) Then
- 'match has been found:
- Security = Decryption(loginFields(5)) 'sets the access level to the lowest to allow the next form to be accessed
- usernameMatch = True
- passwordMatch = True
- match = True 'checks if the input data matches any data in the textfile
- Exit While 'ends the loop as a match has been found
- End If
- If username = UCase(Decryption(loginFields(1))) Then
- usernameMatch = True 'username is correct
- End If
- If password = UCase(Decryption(loginFields(2))) Then
- passwordMatch = True 'password is correct
- End If
- End While
- If passwordMatch = False Then
- MsgBox("Incorrect password, please try again")
- txt_Password.Clear()
- End If
- If usernameMatch = False Then
- MsgBox("Incorrect username, please try again")
- txt_Username.Clear()
- End If
- sr.Close() 'closes streamreader to avoid data loss
- If match = True Then 'if a match has been found:
- Me.Visible = False
- LibraryMenu.Visible = True
- End If
- End Sub
- Private Sub pbx_ExitButton_Click(sender As Object, e As EventArgs) Handles pbx_ExitButton.Click
- If MsgBox("Are you sure you want to quit the program?", vbYesNo) = vbYes Then
- 'when the exit button is clicked, exit the program if yes is selected
- Application.Exit() 'closes the program
- End If
- End Sub
- Private Sub btn_Forgotten_Click(sender As Object, e As EventArgs) Handles btn_Forgotten.Click
- Me.Visible = False 'hides the login form
- ForgottenPassword.Visible = True 'shows the forgotten password form
- End Sub
- Private Sub btn_Help_Click(sender As Object, e As EventArgs) Handles btn_Help.Click
- Help.txt_help.Text = "This is the login form. Input your username into the username textbox, and input your password into the password textbox," _
- & " 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" _
- & " forgotten your password, then you can click on the 'forgotten password' button to be redirected to that form. If you click the cross button" _
- & " in the top right of the form, you will exit the program."
- Help.Show()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement