Advertisement
UsernameHere1

Untitled

Feb 21st, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.03 KB | None | 0 0
  1. Imports System.IO 'import the inputs and outputs for the program
  2.  
  3. Public Class CreateAccount 'Create account form
  4.     Private Sub CreateAccount_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'when form loads
  5.         Me.CenterToScreen() 'centre form to screen
  6.         Dim startupPath As String 'store the location the program is running
  7.         startupPath = Application.StartupPath
  8.         pbx_logo.ImageLocation = startupPath & "\PennardLibraryLogo.png" 'set up the logo image location
  9.         pbx_back.ImageLocation = startupPath & "\Arrow.png" 'set the back image location
  10.         Me.BackColor = Color.FromArgb(163, 255, 166) 'Set the background to the standard light green
  11.     End Sub
  12.     Private Sub pbx_back_MouseHover(sender As Object, e As EventArgs) Handles pbx_back.MouseHover 'rollover when hovered
  13.         Dim startupPath As String 'store the location the program is running
  14.         startupPath = Application.StartupPath
  15.         pbx_back.ImageLocation = startupPath & "\ArrowRollover.png" 'load rollover
  16.     End Sub
  17.     Private Sub pbx_back_MouseLeave(sender As Object, e As EventArgs) Handles pbx_back.MouseLeave
  18.         Dim startupPath As String 'store the location the program is running
  19.         startupPath = Application.StartupPath
  20.         pbx_back.ImageLocation = startupPath & "\Arrow.png" 'change to normal image
  21.     End Sub
  22.     Private Sub pbx_back_Click(sender As Object, e As EventArgs) Handles pbx_back.Click
  23.         Dim Login As New Login 'new instance of login form
  24.         Login.Show() 'show new form
  25.         Me.Close()  'close current form
  26.     End Sub
  27.     Private Sub txt_username_MouseClick(sender As Object, e As MouseEventArgs) Handles txt_username.MouseClick
  28.         If txt_username.Text = "Username" Then 'Make text in the textbox that dissapears when clicked
  29.             txt_username.Text = "" 'clear textbox
  30.         End If
  31.     End Sub
  32.     Private Sub txt_password_MouseClick(sender As Object, e As EventArgs) Handles txt_password.MouseClick
  33.         If txt_password.Text = "Password" Then 'if text is the starting text
  34.             txt_password.Text = "" 'clear textbox
  35.         End If
  36.     End Sub
  37.     Private Sub btn_createAccount_Click(sender As Object, e As EventArgs) Handles btn_createAccount.Click
  38.         Dim encryption As New clsEncryption 'instantiate the encryption class
  39.         Dim validation As New clsValidation 'make a new instantiation of the clsValidation class
  40.         Dim validated As Boolean = True 'make a variable that will ensure all validation requirments are met
  41.         Dim record As String 'a record from the file
  42.         Dim fields() As String 'the fields in the record
  43.         Dim addAccountID As Integer = 0 'the accountID to be added
  44.         Dim sr As New StreamReader("loginData.txt") 'a stream reader of the login data file
  45.         While sr.Peek() >= 0 'while there are records in the file
  46.             record = encryption.decrypt(sr.ReadLine) 'decrypt the record
  47.             fields = record.Split(",") 'split the record into fields
  48.             If fields(0) >= addAccountID Then 'if the record has a higher ID than the new ID
  49.                 addAccountID = fields(0) + 1 'makes sure that the accountID being added is always 1 higher than the largest one stored
  50.             End If
  51.         End While
  52.         sr.Close() 'close the stream reader
  53.         Dim addUsername As String 'the new username to be added
  54.         Dim addPassword As String 'the new password to be added
  55.         Dim addLevelOfAccess As Integer 'the new level of access to be added
  56.         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
  57.             validated = False 'validation isnt met
  58.             MsgBox("Data cannot contain commas") 'notify user
  59.         End If
  60.         If validation.presenceCheck(txt_username.Text) = True And txt_username.Text <> "Username" Then 'if the value returned by the method of clsValidation is True
  61.             If validation.lengthCheck(txt_username.Text, 50, 5) = True Then 'if the username is between 5 and 50 characters
  62.                 addUsername = txt_username.Text 'allow the text to be added
  63.             Else
  64.                 validated = False 'validation isnt met
  65.                 MsgBox("Username must be between 5 and 50 characters") 'notify user
  66.             End If
  67.         Else
  68.             validated = False 'makes sure the data isnt added if validation rules arent followed
  69.             MsgBox("You need to fill all fields") 'notify user
  70.         End If
  71.         If validation.presenceCheck(txt_password.Text) = True And txt_password.Text <> "Password" Then 'if the value returned by the method of clsValidation is True
  72.             If validation.lengthCheck(txt_password.Text, 50, 5) = True Then 'if password is between 5 and 50 characters
  73.                 addPassword = txt_password.Text 'allow the text to be added
  74.             Else
  75.                 validated = False 'validation isnt met
  76.                 MsgBox("Password must be between 5 and 50 characters") 'notify user
  77.             End If
  78.         Else
  79.             validated = False 'makes sure the data isnt added if validation rules arent followed
  80.             MsgBox("You need to fill all fields") 'notify user
  81.         End If
  82.         addLevelOfAccess = 1 'the new level of access is customer
  83.         If validated = True Then 'if validation is met
  84.             Dim sw As New StreamWriter("loginData.txt", True) 'a stream writer to append the login data file
  85.             sw.WriteLine(encryption.encrypt(addAccountID & "," & addUsername & "," & addPassword & "," & addLevelOfAccess)) 'write a record to the file
  86.             sw.Close() 'close the stream writer
  87.             MsgBox("New user added") 'notift user a record was added
  88.         Else
  89.             MsgBox("You must fit the validation requirements") 'notify user that not all validation is met
  90.         End If
  91.         txt_username.Text = "Username" 'reset text boxes
  92.         txt_password.Text = "Password"
  93.     End Sub
  94. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement