Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO 'import the inputs and outputs for the program
- Public Class CreateAccount 'Create account form
- Private Sub CreateAccount_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'when form loads
- Me.CenterToScreen() 'centre form to screen
- Dim startupPath As String 'store the location the program is running
- startupPath = Application.StartupPath
- pbx_logo.ImageLocation = startupPath & "\PennardLibraryLogo.png" 'set up the logo image location
- pbx_back.ImageLocation = startupPath & "\Arrow.png" 'set the back image location
- Me.BackColor = Color.FromArgb(163, 255, 166) 'Set the background to the standard light green
- End Sub
- Private Sub pbx_back_MouseHover(sender As Object, e As EventArgs) Handles pbx_back.MouseHover 'rollover when hovered
- Dim startupPath As String 'store the location the program is running
- startupPath = Application.StartupPath
- pbx_back.ImageLocation = startupPath & "\ArrowRollover.png" 'load rollover
- End Sub
- Private Sub pbx_back_MouseLeave(sender As Object, e As EventArgs) Handles pbx_back.MouseLeave
- Dim startupPath As String 'store the location the program is running
- startupPath = Application.StartupPath
- pbx_back.ImageLocation = startupPath & "\Arrow.png" 'change to normal image
- End Sub
- Private Sub pbx_back_Click(sender As Object, e As EventArgs) Handles pbx_back.Click
- Dim Login As New Login 'new instance of login form
- Login.Show() 'show new form
- Me.Close() 'close current form
- End Sub
- Private Sub txt_username_MouseClick(sender As Object, e As MouseEventArgs) Handles txt_username.MouseClick
- If txt_username.Text = "Username" Then 'Make text in the textbox that dissapears when clicked
- txt_username.Text = "" 'clear textbox
- End If
- End Sub
- Private Sub txt_password_MouseClick(sender As Object, e As EventArgs) Handles txt_password.MouseClick
- If txt_password.Text = "Password" Then 'if text is the starting text
- txt_password.Text = "" 'clear textbox
- End If
- End Sub
- Private Sub btn_createAccount_Click(sender As Object, e As EventArgs) Handles btn_createAccount.Click
- Dim encryption As New clsEncryption 'instantiate the encryption class
- Dim validation As New clsValidation 'make a new instantiation of the clsValidation class
- Dim validated As Boolean = True 'make a variable that will ensure all validation requirments are met
- Dim record As String 'a record from the file
- Dim fields() As String 'the fields in the record
- Dim addAccountID As Integer = 0 'the accountID to be added
- Dim sr As New StreamReader("loginData.txt") 'a stream reader of the login data file
- While sr.Peek() >= 0 'while there are records in the file
- record = encryption.decrypt(sr.ReadLine) 'decrypt the record
- fields = record.Split(",") 'split the record into fields
- If fields(0) >= addAccountID Then 'if the record has a higher ID than the new ID
- addAccountID = fields(0) + 1 'makes sure that the accountID being added is always 1 higher than the largest one stored
- End If
- End While
- sr.Close() 'close the stream reader
- Dim addUsername As String 'the new username to be added
- Dim addPassword As String 'the new password to be added
- Dim addLevelOfAccess As Integer 'the new level of access to be added
- If validation.characterCheck(txt_username.Text, ",") = False Or validation.characterCheck(txt_password.Text, ",") = False Then 'doesnt allow commas to be entered as it would make it records be split wrong in reading
- validated = False 'validation isnt met
- MsgBox("Data cannot contain commas") 'notify user
- End If
- If validation.presenceCheck(txt_username.Text) = True And txt_username.Text <> "Username" Then 'if the value returned by the method of clsValidation is True
- If validation.lengthCheck(txt_username.Text, 50, 5) = True Then 'if the username is between 5 and 50 characters
- addUsername = txt_username.Text 'allow the text to be added
- Else
- validated = False 'validation isnt met
- MsgBox("Username must be between 5 and 50 characters") 'notify user
- End If
- Else
- validated = False 'makes sure the data isnt added if validation rules arent followed
- MsgBox("You need to fill all fields") 'notify user
- End If
- If validation.presenceCheck(txt_password.Text) = True And txt_password.Text <> "Password" Then 'if the value returned by the method of clsValidation is True
- If validation.lengthCheck(txt_password.Text, 50, 5) = True Then 'if password is between 5 and 50 characters
- addPassword = txt_password.Text 'allow the text to be added
- Else
- validated = False 'validation isnt met
- MsgBox("Password must be between 5 and 50 characters") 'notify user
- End If
- Else
- validated = False 'makes sure the data isnt added if validation rules arent followed
- MsgBox("You need to fill all fields") 'notify user
- End If
- addLevelOfAccess = 1 'the new level of access is customer
- If validated = True Then 'if validation is met
- Dim sw As New StreamWriter("loginData.txt", True) 'a stream writer to append the login data file
- sw.WriteLine(encryption.encrypt(addAccountID & "," & addUsername & "," & addPassword & "," & addLevelOfAccess)) 'write a record to the file
- sw.Close() 'close the stream writer
- MsgBox("New user added") 'notift user a record was added
- Else
- MsgBox("You must fit the validation requirements") 'notify user that not all validation is met
- End If
- txt_username.Text = "Username" 'reset text boxes
- txt_password.Text = "Password"
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement