VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Simple & Easy Password Protection, With the option to change password

by Michael Leach (2 Submissions)
Category: Encryption
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This protects a form or program by adding a login form or protection to a form. It also includes a form which enables you to change the password.
NOTE: This should not be used as HIGH security as it can be hacked by simply looking in the registry. Good for newbies and begginers though. Please vote for me!!

Assumes
Very little knowledge required, just some knoewledge of the VB Interface, thats all.
API Declarations
None.

Rate Simple & Easy Password Protection, With the option to change password

NOTE: The First Password will be "", or Nothing,
as there is nothing saved to that setting in the registry untill you change the password.
NOTE: See ScreenShot for info on setting the forms
up and the controls to be put on to the forms.
==================================
Put this code in the "LOGIN" form:
===================================
Private Sub cmdlogin_Click()
If txtPassword.Text = txtgetpass.Text Then
  frmMain.Show
  Unload Me
Else
  MsgBox "Invalid Password, Please try again", , "Login"
  txtPassword.Text = ""
  txtPassword.SetFocus
End If
End Sub
Private Sub Form_Load()
txtgetpass.Text = GetSetting("App", "Appname", "Password", "")
End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
  'If enter was pressed in the text box that inputs a message to send, simulate the pressing of the Send button.
  cmdlogin_Click
  'Clear the text box.
  KeyAscii = 0
End If
End Sub
==================================================
Put this code in the "ChangePassword form" :
==================================================
Private Sub txtoldpassword_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
  'If enter was pressed in the text box that inputs a message to send, simulate the pressing of the Send button.
  txtnewpassword.SetFocus
  'Clear the text box.
  KeyAscii = 0
End If
End Sub
Private Sub txtnewpassword_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
  'If enter was pressed in the text box that inputs a message to send, simulate the pressing of the Send button.
  txtchknewpass.SetFocus
  'Clear the text box
  KeyAscii = 0
End If
End Sub
Private Sub txtchknewpass_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
  'If enter was pressed in the text box that inputs a message to send, simulate the pressing of the Send button.
  Command1_Click
  'Clear the text box
  KeyAscii = 0
End If
End Sub

Private Sub Command1_Click()
If txtoldpassword.Text = " " Then
  MsgBox "Please enter old password", vbOKOnly, "Login"
Else
  GoTo Checkoldpass
End If
Exit Sub
Checkoldpass:
If txtoldpassword = txtgetpass.Text Then
  GoTo checknewPass
Else
  MsgBox "Invalid Old Password, Please try again", vbOKOnly, "Login"
End If
Exit Sub
checknewPass:
If txtnewpassword.Text = "" Then
  MsgBox "Please enter a new password", vbOKOnly, "Login"
Else
  GoTo Confirmpass
End If
Exit Sub
Confirmpass:
If txtnewpassword.Text = txtchknewpass.Text Then
  GoTo Changepass
Else
  MsgBox "Password's do not match",,"Login"
End If
Exit Sub
Changepass:
SaveSetting "App", "Appname", "Password", txtchknewpass.Text
MsgBox "Password succesfully changed!", vbOKOnly, "Login"
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
txtgetpass.Text = GetSetting("App", "AppName", "Password", "")
End Sub

Download this snippet    Add to My Saved Code

Simple & Easy Password Protection, With the option to change password Comments

No comments have been posted about Simple & Easy Password Protection, With the option to change password. Why not be the first to post a comment about Simple & Easy Password Protection, With the option to change password.

Post your comment

Subject:
Message:
0/1000 characters