Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO 'imports library to allow the use of stream reader/writer
- Public Class ForgottenPassword
- Dim securityAnswer As String 'creates new string variable to store the security answer of the user
- Dim password As String 'creates new string variable to store the password of the user
- Dim securityQuestion As String 'creates new string variable to store the security question of the user
- Private Sub pbx_ExitButton_Click(sender As Object, e As EventArgs) Handles pbx_ExitButton.Click
- If MsgBox("Are you sure you want to exit to the login form?", vbYesNo) = vbYes Then
- 'when the exit button is clicked, exit the program if yes is selected
- Dim Login As New Login 'creates new login form
- Login.Show() 'shows the login form
- Me.Close() 'exits the current form
- End If
- End Sub
- Private Sub btn_Search_Click(sender As Object, e As EventArgs) Handles btn_Search.Click
- Dim username As String 'creates a string variabe to store the username
- Dim currentUser As String 'creates a string variable to store the current user information
- Dim loginFields() As String 'creates an array to store the information input into the login fields
- Dim match As Boolean = False 'creates a boolean variable to check if username and password match later on, set to false to begin with
- username = UCase(txt_Username.Text) 'sets the username variable to an uppercase version of the username in textbox
- If username = "" Then 'if the username textbox is clear
- MsgBox("Enter your username into the username texbox to search for password") 'shows message to ask user to input data into username texbox
- txt_Username.Clear() 'clears username 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 hasn't reached the end:
- 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 username = UCase(Decryption(loginFields(1))) Then 'if the data in the textbox matches the first field of the currently selected record in the login text file, then:
- 'match has been found:
- securityQuestion = Decryption(loginFields(6)) 'the security quesiton variablehas the data from the corresponfing field stored in it
- securityAnswer = Decryption(loginFields(7)) 'the security answer variable has the data from the corresponfing field stored in it
- password = Decryption(loginFields(2)) 'the password variable has the data from the corresponfing field stored in it
- Security = Decryption(loginFields(5)) 'sets the access level to the lowest to allow the next form to be accessed
- 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
- End While
- sr.Close() 'closes streamwriter to avoid data loss
- If match = True Then 'if a match has been found:
- MsgBox("Account found. Please answer your security question below") 'shows a message box to tell the user that the account is found
- txt_SecurityQuestion.Text = securityQuestion 'puts the data stored in the securityQuesiton variable in the textbox
- Else
- MsgBox("No match found. Please try again with a different username") 'shows a message box to tell the user that a match hasn't been found
- 'clears all textboxes
- txt_Username.Clear()
- txt_Answer.Clear()
- txt_SecurityQuestion.Clear()
- End If
- End Sub
- Private Sub btn_Enter_Click(sender As Object, e As EventArgs) Handles btn_Enter.Click
- If txt_Answer.Text = securityAnswer Then 'if the answer entered by the user matches the correct answer, then:
- MsgBox("Security answer is correct. Your password is:" & password) 'shows a message box to tell the user thier password
- MsgBox("Please log in again.") 'shows a message box to prompt the user to log in again
- Me.Visible = False 'hides the current form
- Login.Visible = True 'shows the login form
- 'clears data in textboxes in case the form is reopened
- txt_Username.Clear()
- txt_Answer.Clear()
- txt_SecurityQuestion.Clear()
- Else
- MsgBox("Security answer is incorrect. Please try again.") 'shows a message box to tell the user that their answer was incorrect
- txt_Answer.Clear() 'clears the answer textbox
- End If
- End Sub
- Private Sub btn_Help_Click(sender As Object, e As EventArgs) Handles btn_Help.Click
- Help.txt_help.Text = "This is the forgotten password form. You will need to input your username into the username textbox, then click the search button. " _
- & "If the username matches an existing one in the database, the security question linked to that account will be shown. Answer this question in the security answer textbox below. " _
- & "If the answer is correct, your password will be shown on screen. If it is incorrect, you can either try again, or exit back to the login form using the cross button in the top right"
- Help.Show()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement