Advertisement
UsernameHere1

Untitled

Feb 21st, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.29 KB | None | 0 0
  1. Imports System.IO 'import input and output features
  2. Imports System.Security.Cryptography.X509Certificates
  3. Public Class Login 'login form
  4.     Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'when form loads
  5.         Dim encryption As New clsEncryption 'instantiates the encryption class
  6.         Me.CenterToScreen() 'centre the form to the screen
  7.         Dim startupPath As String
  8.         startupPath = Application.StartupPath 'Find where the file is running
  9.         Me.BackColor = Color.FromArgb(163, 255, 166) 'Set the background to the standard light green
  10.         pbx_logo.ImageLocation = startupPath & "\PennardLibraryLogo.png" 'Set up logo image
  11.         pbx_exit.ImageLocation = startupPath & "\Exit.png" 'set up exit image
  12.         If Dir(startupPath & "\loginData.txt") = "" Then 'if file doesnt exist
  13.             Dim sw As New StreamWriter("loginData.txt", True) 'Stream writer of login data file
  14.             sw.WriteLine(encryption.encrypt("1,AutoAdmin,PennardLibraryAdmin,3")) 'Set an admin account to always be there so that all data can be edited
  15.             sw.WriteLine(encryption.encrypt("2,AutoLibrarian,PennardLibraryLibrarian,2")) 'set a librarian account
  16.             sw.Close() 'close stream writer
  17.             MsgBox("Login Details File Created.") 'notify user a file was made
  18.         End If
  19.     End Sub
  20.  
  21.     Private Sub txt_username_MouseClick(sender As Object, e As MouseEventArgs) Handles txt_username.MouseClick 'when textbox clicked
  22.         If txt_username.Text = "Username" Then 'Make text in the textbox that dissapears when clicked
  23.             txt_username.Text = "" 'makes text dissapear
  24.         End If
  25.     End Sub
  26.  
  27.     Private Sub txt_password_MouseClick(sender As Object, e As EventArgs) Handles txt_password.MouseClick 'when textbox click
  28.         If txt_password.Text = "Password" Then 'if text is the start text
  29.             txt_password.Text = "" 'clear textbox
  30.         End If
  31.     End Sub
  32.  
  33.     Private Sub btn_login_Click(sender As Object, e As EventArgs) Handles btn_login.Click
  34.         Dim encryption As New clsEncryption 'instantiate the encryption class
  35.         Dim found As Boolean 'has the record been found
  36.         found = False 'record is not found to start
  37.         Dim searchUsername As String 'the username to be searched for
  38.         Dim searchPassword As String 'the password to be searched for
  39.         Dim record As String 'a single record from the file
  40.         Dim fields() As String 'the fields in the record
  41.         searchUsername = txt_username.Text 'find the values that are being searched for
  42.         searchPassword = txt_password.Text
  43.         Dim sr As New StreamReader("loginData.txt") 'read from the file of login details
  44.         While sr.Peek() >= 0 'Checks every line
  45.             record = encryption.decrypt(sr.ReadLine) 'store on record from the file as a variable
  46.             fields = record.Split(",") 'split up the record into an array
  47.             If fields(1) = searchUsername And searchPassword = fields(2) Then 'if the username and password being searched for are in the system'
  48.                 accountID = fields(0) 'Store the currently logged in customer details for use later
  49.                 username = fields(1)
  50.                 password = fields(2)
  51.                 levelOfAccess = fields(3)
  52.                 found = True
  53.             End If
  54.         End While
  55.         If found = True Then 'if it has been found
  56.             txt_username.Text = "Username" 'reset the text boxes
  57.             txt_password.Text = "Password"
  58.             Dim MainMenu As New MainMenu 'New instance of main menu form
  59.             MainMenu.Show() 'show new form
  60.             Me.Close() 'close current form
  61.         Else
  62.             MsgBox("Login Details Not Found") 'Notify user the details given aren't stored
  63.         End If
  64.         sr.Close()
  65.     End Sub
  66.  
  67.     Private Sub btn_createAccount_Click(sender As Object, e As EventArgs) Handles btn_createAccount.Click
  68.         Dim CreateAccount As New CreateAccount 'New instance of the create account form
  69.         CreateAccount.Show() 'show new form
  70.         Me.Close() 'close current form
  71.     End Sub
  72.  
  73.     Private Sub btn_forgottenPassword_Click(sender As Object, e As EventArgs) Handles btn_forgottenPassword.Click
  74.         Dim ForgottenPassword As New ForgottenPassword 'new instance of the forgotten password form
  75.         ForgottenPassword.Show() 'show the new form
  76.         Me.Close() 'close the current form
  77.     End Sub
  78.     Private Sub pbx_exit_MouseHover(sender As Object, e As EventArgs) Handles pbx_exit.MouseHover
  79.         Dim startupPath As String 'store the location the program is running
  80.         startupPath = Application.StartupPath
  81.         pbx_exit.ImageLocation = startupPath & "\ExitRollover.png" 'When the mouse is hovering over use the darkened version of the image
  82.     End Sub
  83.  
  84.     Private Sub pbx_exit_MouseLeave(sender As Object, e As EventArgs) Handles pbx_exit.MouseLeave
  85.         Dim startupPath As String 'store the location the program is running
  86.         startupPath = Application.StartupPath
  87.         pbx_exit.ImageLocation = startupPath & "\Exit.png" 'When the mouse is no longer hovering change back to the standard image
  88.     End Sub
  89.     Private Sub pbx_exit_Click(sender As Object, e As EventArgs) Handles pbx_exit.Click
  90.         Application.Exit() 'Close the program
  91.     End Sub
  92. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement