Verifying Password in a form (1 Viewer)

tamangspace

Registered User.
Local time
Today, 20:10
Joined
Jul 15, 2012
Messages
37
Hello guys,
I created a login form using the below code. I got the code in this FORUM. thanks for you all. It works perfectly. I don't know how to create codes in vb. I started to read through this forum and learning a bit.

Now I want to create another login form. It would work for password change if any user forgets his password. I used the code to verify 'secret word' and open the 'password change form'. but it is not working. The MsgBox shows "Invalid Secret Word" even if secret word is correct. I paste the code below.

Option Compare Database

'********************************
'********************************
'*** ***
'*** Created by Tamangspace ***
'*** ***
'********************************
'********************************

Private intLogAttempt As Integer

Private Sub cboUser_GotFocus()

cboUser.Dropdown

End Sub

Private Sub cmdExit_Click()

MsgBox "Are you really want to exit this application?"
If response = vbYes Then
Application.Quit
End If

End Sub

Private Sub cmdLogin_Click()

Call Login

End Sub

Private Sub cmdLogin_Enter()

Call Login

End Sub

Public Sub Form_Load()

txtFocus.SetFocus 'txtFocus is a textbox control with height, width and positions set to zero

End Sub

Public Sub Login()

On Error GoTo ErrorHandler:

If IsNull([cboUser]) = True Then 'Check UserName
MsgBox "Username is required"

ElseIf IsNull([txtSecret]) = True Then 'Check Secret word
MsgBox "Secret Word is required"

Else
'secretword is to verify users to change their informations. In frmUsers, a user can change his password.
'Compare value of txtSecret with the saved Secret Word in tblUsers
If Me.txtSecret.Value = DLookup("Secret", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
DoCmd.Close acForm, "Secret", acSaveNo
MsgBox "Welcome to Password Area, " & strUser, vbOKOnly, "Welcome"
DoCmd.OpenForm "frmUsers", acNormal, "", "", , acNormal

Else
MsgBox "Invalid Secret Word. Please try again.", vbOKOnly, "Invalid password"
intLogAttempt = intLogAttempt + 1
txtSecret.SetFocus

End If

End If

'Check if the user has 3 wrong log-in attempts and close the application
If intLogAttempt = 3 Then
MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
"Application will exit.", vbCritical, "Restricted Access!"
Application.Quit
End If

ErrorHandler:

End Sub

Please be notified that, the same is used for User Login form and its perfect. But in password form it doesn't verify secret word.

Any help is most appreciated.

Thank you all in advance.

<tamangspace>
 

rodmc

Registered User.
Local time
Today, 17:10
Joined
Apr 15, 2010
Messages
514
I dont let them change passwords themselves, I have in the past but like all users they tend to screw it up and I end up doing it in the end anyway.
 

tamangspace

Registered User.
Local time
Today, 20:10
Joined
Jul 15, 2012
Messages
37
Dear rod,
Thanks for a quick response. But if they forgot their password, how do they reset password?

I mean I want to give the right to change their password themselves.
hope to your response.

Tamangspace
 

rodmc

Registered User.
Local time
Today, 17:10
Joined
Apr 15, 2010
Messages
514
they dont, you do it for them or have someone you can trust do it for them.

What you'll find is they'll reset there pasword with a typo in it, and then they'll say they cant log in.

Plus it means you can define a strong pasword, instead of the users favourite football team or any other password that can be easily guessed.

Rod
 

Accessensible

New member
Local time
Today, 19:10
Joined
Sep 6, 2012
Messages
4
Well, this code works as expected.
Basically I have a form with four fields.
1. username
2. old password (you can call it secretwoord if u like.)
3. new password
4. confirmation

sorry, some text in de messages is in a foreign language.
but u'll get the idea:cool:

Private Sub B_Login_Click()
Dim varX As Variant
'Check to see if data is entered into the UserName combo box
If IsNull(Me.T_username) Or Me.T_username = "" Then
MsgBox "Username must be filled.", vbOKOnly, "Data Verplicht"
' Me.T_username.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.T_wachtwoord) Or Me.T_wachtwoord = "" Then
MsgBox "Old password must be filled.", vbOKOnly, "Data verplicht"
Me.T_wachtwoord.SetFocus
Exit Sub
End If

'Check value of password in Medewerkers table to see if it matches
varX = DLookup("[Med_Wachtwoord]", "Medewerkers", "[Med_code] = '" + Me.T_username + "'")
If varX = Me.T_wachtwoord.value Then
' MsgBox varX, vbOKOnly
Else
MsgBox "Verkeerde Wachtwoord", vbOKOnly
Me.T_wachtwoord.SetFocus
Exit Sub
End If

'Check If data is entered into the New password box
If IsNull(Me.T_NWachtwoord) Or Me.T_NWachtwoord = "" Then
MsgBox "Nieuwe Wachtwoord moet worden ingevuld.", vbOKOnly, "Data verplicht"
Me.T_NWachtwoord.SetFocus
Exit Sub
Else
' MsgBox Me.T_NWachtwoord, vbOKOnly
End If

'Check If data is entered into the password Confirmation box
If IsNull(Me.T_cwachtwoord) Or Me.T_cwachtwoord = "" Then
MsgBox "Wachtwoord Bevestiging moet worden ingevuld.", vbOKOnly, "Data verplicht"
Me.T_cwachtwoord.SetFocus
Exit Sub
Else
' MsgBox Me.T_cwachtwoord, vbOKOnly
If Me.T_NWachtwoord <> Me.T_cwachtwoord Then
MsgBox "Wachtwoord Bevestiging is niet gelijk aan het wachtwoord", vbOKOnly, "Mismatch"
Exit Sub
Else
varY = DLookup("[Med_code]", "Medewerkers", "[Med_code] = '" + Me.T_username + "'")
CurrentDb.Execute "UPDATE medewerkers SET Med_wachtwoord = '" & Me.T_cwachtwoord & "' Where Med_code = '" & varY & "'"
' MsgBox varY, vbOKOnly
MsgBox "Uw wachtwoord is gewijzigd.", vbOKOnly
DoCmd.Close acForm, "ChangePassword", acSaveNo
End If

End If

End Sub
 

tamangspace

Registered User.
Local time
Today, 20:10
Joined
Jul 15, 2012
Messages
37
Thanks a lot.
But why do you not write this code in International language? I mean it is so difficult to understand what is there!. And I tried your code but not successful. Sorry. and Thank you again.
 

Users who are viewing this thread

Top Bottom