I have set up a customized security system for my database. The problem that I am running into is in the instance that I ask my users to change their passwords. If the user uses a new password that has the same number of characters as the old password, the code rejects it saying that the passwords haven't been changed. But, the actual text and the password does change if I change the password to a value that is shorter or longer than the old password. Below is the code that I am using for the change password button.
Private Sub cmdChangePwd_Click()
'Create variables
Dim strOldPwd As String 'Original Database password
Dim strConfirmOldPwd As String 'Database confirmation password
Dim strNewPwd As String 'New database password
Dim strConfirmNewPwd As String 'New database password confirmation
'set focus to old password
Me.Password.SetFocus
strOldPwd = Me.Password.Text
'set focus to confirm
Me.txtOldPwd.SetFocus
strConfirmOldPwd = Me.txtOldPwd.Text
'Set focus to new db password
Me.txtNewPwd.SetFocus
strNewPwd = Me.txtNewPwd.Text
If strNewPwd = strOldPwd Then
MsgBox ("You must change your password.")
'Clear the new password and new password confirm boxes
Me.txtNewPwd.SetFocus
Me.txtNewPwd.Text = ""
Me.txtConfirmPwd.SetFocus
Me.txtConfirmPwd.Text = ""
Me.txtNewPwd.SetFocus 'set focus to new password textbox
Else
If strOldPwd = strConfirmOldPwd Then 'Check for matching old passwords
'Set db to confirm new db password
Me.txtConfirmPwd.SetFocus
strConfirmNewPwd = Me.txtConfirmPwd.Text
If strNewPwd = strConfirmNewPwd Then
Me.Password.SetFocus
Me.Password.Text = strConfirmNewPwd
'Display confirmation box and close password change form.
MsgBox ("Your password has been changed.")
DoCmd.Close acForm, "frmChangePassword", acSaveYes
Else
MsgBox ("Your new passwords do not match.")
Me.txtNewPwd.SetFocus
Me.txtNewPwd.Text = ""
Me.txtConfirmPwd.SetFocus
Me.txtConfirmPwd.Text = ""
End If
Else
MsgBox ("Your original password does not match our records.")
Me.txtOldPwd.SetFocus
Me.txtOldPwd.Text = ""
End If
End If
End Sub
Thank you,
Brian
Private Sub cmdChangePwd_Click()
'Create variables
Dim strOldPwd As String 'Original Database password
Dim strConfirmOldPwd As String 'Database confirmation password
Dim strNewPwd As String 'New database password
Dim strConfirmNewPwd As String 'New database password confirmation
'set focus to old password
Me.Password.SetFocus
strOldPwd = Me.Password.Text
'set focus to confirm
Me.txtOldPwd.SetFocus
strConfirmOldPwd = Me.txtOldPwd.Text
'Set focus to new db password
Me.txtNewPwd.SetFocus
strNewPwd = Me.txtNewPwd.Text
If strNewPwd = strOldPwd Then
MsgBox ("You must change your password.")
'Clear the new password and new password confirm boxes
Me.txtNewPwd.SetFocus
Me.txtNewPwd.Text = ""
Me.txtConfirmPwd.SetFocus
Me.txtConfirmPwd.Text = ""
Me.txtNewPwd.SetFocus 'set focus to new password textbox
Else
If strOldPwd = strConfirmOldPwd Then 'Check for matching old passwords
'Set db to confirm new db password
Me.txtConfirmPwd.SetFocus
strConfirmNewPwd = Me.txtConfirmPwd.Text
If strNewPwd = strConfirmNewPwd Then
Me.Password.SetFocus
Me.Password.Text = strConfirmNewPwd
'Display confirmation box and close password change form.
MsgBox ("Your password has been changed.")
DoCmd.Close acForm, "frmChangePassword", acSaveYes
Else
MsgBox ("Your new passwords do not match.")
Me.txtNewPwd.SetFocus
Me.txtNewPwd.Text = ""
Me.txtConfirmPwd.SetFocus
Me.txtConfirmPwd.Text = ""
End If
Else
MsgBox ("Your original password does not match our records.")
Me.txtOldPwd.SetFocus
Me.txtOldPwd.Text = ""
End If
End If
End Sub
Thank you,
Brian