password input mask problem

b9791

Brian
Local time
Today, 01:05
Joined
Jul 30, 2002
Messages
29
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
 
Read up on events and event procedures in Access Help. Your code needs to be split up into event procedures for these text boxes. You may not even need the command button. How does a user get to this form if they have not already entered a valid password once. I like to display the user name on forms from time to time; to do that I use a public variable, "UserOn", or something like that. (Declare it in a module.) If you know what user is logged in, you can look up the password for that user when your form opens. If change password is the only function of the form, then you know why it is open. No button?
 
The form in question is strictly for changing passwords. It is set up in the following way.

The user logs into the database and after logging in the login form stores their username in a global variable in a module. The change password form is called in one of two ways. (1) The user initiates it on the menu, or (2) the database opens it if it is the users first time logging in or the 30th, etc time that they have logged in.

The change password form filters the data in the OnLoad Event for users by the global variable strUserName. I have the username and password fields hidden on the form in order to verify that the new password is not the same as the old password.

My problem however, is that if a users password is "password1" and they change it to "password2" the code or input mask is rejecting it with the MsgBox response that you must change your password.

Is this because I am using an input mask for all of the textboxes and somehow access is not comparing the actual data, but instead the number of *'s? If so, what is the workaround?
 
Mmmmm. I would like to see your form and the structure of your table. Is the current password already at max field length?
Open your form in design view and (temporarily) clear out the password input masks so you can see what's going on. This error message, it must be coming from an event triggered by something on YOUR form. Find that code and set a break point there so you can see all the variable values. (The code will be behind a control or a form event.)
 
You should NOT be using the .text property. Remove the property entirely or use .value instead. .Value is the default property which is why it can be omitted. The .text property in VBA objects is very different from .text in VB. Read help for further discussion.

PS, when you stop using the .text property, you can also remove the .SetFocus statements since they were only necessary when you were referencing the .test peroperty.
 
Last edited:
Wow! Did I over look the obvious! A great lesson for both of us in why this forum exists and is so great.
 
Thank you Pat! That worked perfectly.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom