User Change Password Form

thedys

New member
Local time
Today, 13:06
Joined
Jan 11, 2017
Messages
7
I'm trying to create a form that allows user to change their passwords, however the form doesn't seem to do anything other than give me the msg boxes where am I going wrong?

The code I'm using is

Private Sub btnUpdatepassword_Click()
If Me.txtPassword.Value = DLookup("Password", "tblStaff", "[UserName]= """ & Me.txtUserName & """") Then
GoTo Line1:
Else: MsgBox ("Password Is Incorrect")
End If

Line1:
If (Me.txtNewPassword1 = Me.txtNewPassword1) Then
CurrentDb.Execute "UPDATE tblStaff " _
& "Set Password = 'Me.txtNewPassword1'" _
& "Where UserName = 'Me.txtUserName';"
MsgBox ("Your password has now been updated")

Else
MsgBox "New password does not match"


End If



End Sub
 
The SQL is running, but not changing anything because nothing matches. In your update SQL, you have to concatenate the values from the form into the string, as you did in the DLookup().

By the way, your If statements compares a textbox to itself, so it will always match.
 
Are they in the correct order before I concatenate them?
 
Not sure what you mean. It looks like the correct elements will be there for an update query.
 
Thanks for that with your help I've got it working. I watched a youtube tutorial on hashing passwords using an Encrypt function I was wondering if you could tell me where I'd put the Encrypt function in the above code?
 
I've never used one. Presumably either before the SQL, putting it in a string, or in the SQL, like:

& "Set Password = '" & YourFunction(Me.txtNewPassword1) & "'" _
 
Also be aware of something I found out today with my code.
Code:
If Me.txtUserPassword <> Me.cboEmployeeID.Column(2) Then
    MsgBox "Invalid Password "
    ilogins = ilogins + 1
    Me.txtUserPassword = ""
    Me.txtUserPassword.SetFocus
    If ilogins > 2 Then
        DoCmd.Quit
    End If
 End If

I had tested Me.txtUserPassword with various values and it all worked fine.
However a novice user clicked the Login button without entering anything in the password control and it let him straight in. This was due to the control being Null.:banghead:

I *thought* Null would be different from the password stored, but it appears not the case, so I used Nz(Me.txtUserPassword,"InvalidPassword") to get past this error of mine.:)

I'm trying to create a form that allows user to change their passwords, however the form doesn't seem to do anything other than give me the msg boxes where am I going wrong?

The code I'm using is

Private Sub btnUpdatepassword_Click()
If Me.txtPassword.Value = DLookup("Password", "tblStaff", "[UserName]= """ & Me.txtUserName & """") Then
GoTo Line1:
Else: MsgBox ("Password Is Incorrect")
End If

Line1:
If (Me.txtNewPassword1 = Me.txtNewPassword1) Then
CurrentDb.Execute "UPDATE tblStaff " _
& "Set Password = 'Me.txtNewPassword1'" _
& "Where UserName = 'Me.txtUserName';"
MsgBox ("Your password has now been updated")

Else
MsgBox "New password does not match"


End If



End Sub
 

Users who are viewing this thread

Back
Top Bottom