Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save xSystemIOx/80655500404481b4052f46af25d03378 to your computer and use it in GitHub Desktop.

Select an option

Save xSystemIOx/80655500404481b4052f46af25d03378 to your computer and use it in GitHub Desktop.
Registers a user in the database with password checker
Public Class User_Register
Private Sub Register_Click(sender As Object, e As EventArgs) Handles Register.Click
Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Path")
Dim command As New OleDbCommand("INSERT INTO [Log_in_Info]([Username], [Password]) VALUES(@Username, @Password)", connection) 'SQL query to input values in the database table
Dim usernameparam As New OleDbParameter("@Username", UsernameTXT.Text) 'username parameter
Dim passwordparam As New OleDbParameter("@Password", PasswordTXT.Text) 'password parameter
Dim check As Boolean 'delared variable
Dim pass As String 'delared variable
pass = PasswordTXT.Text
check = PasswordStrength(pass)
If check = False Then 'if variable check is false then it will do the following precedure
MsgBox("Password must be between 8 and 15 characters and must include at least one upper case letter, one lower case letter, and one number.")
PasswordTXT.Clear() 'clear the text box PasswordTXT
Else
If RePasswordTXT.Text = PasswordTXT.Text Then 'if the value in Password2 is equal to the value in PasswordTXT then it will do the following precedure
command.Parameters.Add(usernameparam) 'command parameter
command.Parameters.Add(passwordparam) 'command parameter
command.Connection.Open() 'Opens connection to database
command.ExecuteNonQuery() 'Executes the SQL Statement
command.Connection.Close() 'Closes connection to database
Dim title = "Add User" 'delared variable
MsgBox("User has been added", , title) 'message will display
UsernameTXT.Clear() 'Clears text box
PasswordTXT.Clear() 'Clears tex box
End If
End If
End Sub
Function PasswordStrength(Password As String) As Boolean
If Regex.IsMatch(Password, "^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15}$") Then ' Password must be between 8 and 15 characters and must include at least one upper case letter, one lower case letter, and one number.
Return True 'Password is suitable
Else
Return False 'Password is too weak
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment