Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO 'import input and output features
- Imports System.Security.Cryptography.X509Certificates
- Public Class Login 'login form
- Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'when form loads
- Dim encryption As New clsEncryption 'instantiates the encryption class
- Me.CenterToScreen() 'centre the form to the screen
- Dim startupPath As String
- startupPath = Application.StartupPath 'Find where the file is running
- Me.BackColor = Color.FromArgb(163, 255, 166) 'Set the background to the standard light green
- pbx_logo.ImageLocation = startupPath & "\PennardLibraryLogo.png" 'Set up logo image
- pbx_exit.ImageLocation = startupPath & "\Exit.png" 'set up exit image
- If Dir(startupPath & "\loginData.txt") = "" Then 'if file doesnt exist
- Dim sw As New StreamWriter("loginData.txt", True) 'Stream writer of login data file
- sw.WriteLine(encryption.encrypt("1,AutoAdmin,PennardLibraryAdmin,3")) 'Set an admin account to always be there so that all data can be edited
- sw.WriteLine(encryption.encrypt("2,AutoLibrarian,PennardLibraryLibrarian,2")) 'set a librarian account
- sw.Close() 'close stream writer
- MsgBox("Login Details File Created.") 'notify user a file was made
- End If
- End Sub
- Private Sub txt_username_MouseClick(sender As Object, e As MouseEventArgs) Handles txt_username.MouseClick 'when textbox clicked
- If txt_username.Text = "Username" Then 'Make text in the textbox that dissapears when clicked
- txt_username.Text = "" 'makes text dissapear
- End If
- End Sub
- Private Sub txt_password_MouseClick(sender As Object, e As EventArgs) Handles txt_password.MouseClick 'when textbox click
- If txt_password.Text = "Password" Then 'if text is the start text
- txt_password.Text = "" 'clear textbox
- End If
- End Sub
- Private Sub btn_login_Click(sender As Object, e As EventArgs) Handles btn_login.Click
- Dim encryption As New clsEncryption 'instantiate the encryption class
- Dim found As Boolean 'has the record been found
- found = False 'record is not found to start
- Dim searchUsername As String 'the username to be searched for
- Dim searchPassword As String 'the password to be searched for
- Dim record As String 'a single record from the file
- Dim fields() As String 'the fields in the record
- searchUsername = txt_username.Text 'find the values that are being searched for
- searchPassword = txt_password.Text
- Dim sr As New StreamReader("loginData.txt") 'read from the file of login details
- While sr.Peek() >= 0 'Checks every line
- record = encryption.decrypt(sr.ReadLine) 'store on record from the file as a variable
- fields = record.Split(",") 'split up the record into an array
- If fields(1) = searchUsername And searchPassword = fields(2) Then 'if the username and password being searched for are in the system'
- accountID = fields(0) 'Store the currently logged in customer details for use later
- username = fields(1)
- password = fields(2)
- levelOfAccess = fields(3)
- found = True
- End If
- End While
- If found = True Then 'if it has been found
- txt_username.Text = "Username" 'reset the text boxes
- txt_password.Text = "Password"
- Dim MainMenu As New MainMenu 'New instance of main menu form
- MainMenu.Show() 'show new form
- Me.Close() 'close current form
- Else
- MsgBox("Login Details Not Found") 'Notify user the details given aren't stored
- End If
- sr.Close()
- End Sub
- Private Sub btn_createAccount_Click(sender As Object, e As EventArgs) Handles btn_createAccount.Click
- Dim CreateAccount As New CreateAccount 'New instance of the create account form
- CreateAccount.Show() 'show new form
- Me.Close() 'close current form
- End Sub
- Private Sub btn_forgottenPassword_Click(sender As Object, e As EventArgs) Handles btn_forgottenPassword.Click
- Dim ForgottenPassword As New ForgottenPassword 'new instance of the forgotten password form
- ForgottenPassword.Show() 'show the new form
- Me.Close() 'close the current form
- End Sub
- Private Sub pbx_exit_MouseHover(sender As Object, e As EventArgs) Handles pbx_exit.MouseHover
- Dim startupPath As String 'store the location the program is running
- startupPath = Application.StartupPath
- pbx_exit.ImageLocation = startupPath & "\ExitRollover.png" 'When the mouse is hovering over use the darkened version of the image
- End Sub
- Private Sub pbx_exit_MouseLeave(sender As Object, e As EventArgs) Handles pbx_exit.MouseLeave
- Dim startupPath As String 'store the location the program is running
- startupPath = Application.StartupPath
- pbx_exit.ImageLocation = startupPath & "\Exit.png" 'When the mouse is no longer hovering change back to the standard image
- End Sub
- Private Sub pbx_exit_Click(sender As Object, e As EventArgs) Handles pbx_exit.Click
- Application.Exit() 'Close the program
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement