I can it's just a lot of code.
[[[modUniversal.vb]]]
[[[modLogin.vb]]]Code:Module modUniversal Public state As String = "0" Structure accountInformation Dim ID As Integer Dim username As String Dim permissions As Integer Dim firstName As String Dim middleName As String Dim lastName As String End Structure Public user As accountInformation End Module
[[[login.vb]]]Code:Module modLogin Sub validation(credential As String) Select Case state Case "0" state = "0.1" loginDB("username, password", "username", login.usernameTextbox.Text) Case "0.1" state = "0.2" loginDB("userID, username, permissions, firstName, middleName, lastName", "username", user.username) End Select End Sub End Module
[[[modDatabase_login.vb]]]Code:Public Class login Private Sub login_Load(sender As Object, e As EventArgs) Handles MyBase.Load If My.Settings.rememberedUsername IsNot "" Then usernameTextbox.Text = My.Settings.rememberedUsername rememberMe_checkbox.Checked = True passwordTextbox.Select() End If End Sub Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click Environment.Exit(0) End Sub Private Sub loginButton_Click(sender As Object, e As EventArgs) Handles loginButton.Click Select Case Len(usernameTextbox.Text) >= 7 AndAlso Len(passwordTextbox.Text) >= 10 Case True modDatabase_login.loginDB("username, active", "username", usernameTextbox.Text) Case False If Len(usernameTextbox.Text) < 7 AndAlso Len(passwordTextbox.Text) < 10 Then MessageBox.Show("Invalid username and password length") ElseIf Len(usernameTextbox.Text) < 7 Then MessageBox.Show("Invalid username length") ElseIf Len(passwordTextbox.Text) < 10 Then MessageBox.Show("Invalid password length") End If End Select End Sub Private Sub rememberMe_checkbox_Click(sender As Object, e As EventArgs) Handles rememberMe_checkbox.Click If rememberMe_checkbox.Checked = True Then My.Settings.rememberedUsername = usernameTextbox.Text Else My.Settings.rememberedUsername = "" End If End Sub Private Sub usernameTextbox_TextChanged(sender As Object, e As EventArgs) Handles usernameTextbox.TextChanged If rememberMe_checkbox.Checked = True Then rememberMe_checkbox.Checked = False End If End Sub End Class
Code:Imports System.Data.OleDb Module modDatabase_login ' Make parameter for connection status and applicationEvents can have a test for that connection status but needs a fail-safe for networks without access to the internet. Sub loginDB(columns As String, comparisonColumn As String, comparisonString As String) Dim command As OleDbCommand ' This connection will be created over the network (will have priority of local network if at site to being outside the network completely) when finished and locally for temporary offline use Dim connection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Shawn\Desktop\HPCR.accdb") Dim SQL As String = "SELECT " & columns & " FROM accounts WHERE " & comparisonColumn & " = """ & comparisonString & """" command = New OleDbCommand(SQL, connection) Connection.Open() Dim reader As OleDbDataReader = command.ExecuteReader() If reader.Read() Then Select Case state Case "0" If Convert.ToBoolean(reader("active")) Then user.username = Convert.ToString(reader(comparisonColumn)) validation(comparisonString) Else MessageBox.Show("Account not active") End If Case "0.1" If Convert.ToString(reader("password")) = login.passwordTextbox.Text Then validation(comparisonString) Else state = "0" MessageBox.Show("Invalid password") End If Case "0.2" user.ID = Convert.ToInt32(reader("userID")) user.permissions = Convert.ToInt32(reader("permissions")) user.firstName = Convert.ToString(reader("firstName")) user.middleName = Convert.ToString(reader("middleName")) user.lastName = Convert.ToString(reader("lastName")) login.Hide() mainMenu.Show() login.Close() state = "1" End Select Else state = "0" MessageBox.Show("Invalid username") End If connection.Dispose() connection.Close() login.passwordTextbox.Clear() If state = "0" Then login.passwordTextbox.Focus() End If End Sub End Module




Reply With Quote
