Login and Password change form (1 Viewer)

SShafeeq

Registered User.
Local time
Tomorrow, 00:55
Joined
Jan 4, 2011
Messages
32
Hey,

I have a form which I have used for users to login to the database. This form works well, but i also added a "change your password form".

This form has a combo box which has the user name and three other text boxs (txtOldPW, txtNewPW, txtNewPW2). It also has a change password button too (btnChangedPW).

I have also added a onclick code to the button:

Private Sub btnChangedPw_Click()
Dim PWtocompare As String
PWtocompare = DLookup("Password", "tblLogin", "[ID]=" & Me.txtLoginID.Value)
If txtOldPw = PWtocompare Then
If txtNewPw = TxtNewPw2 Then

Me.txtNewPw.SetFocus
Dim strSQL As String
strSQL = "UPDATE tblLogin SET Password = '" & Me.txtNewPw.Text & "' WHERE ID = txtLoginID"
DoCmd.RunSQL strSQL

Else
MsgBox "Passwords do not match, please re-enter your new password", vbOKOnly, "Passwords do not match"
End If
Else
MsgBox "Current password does not match records. Please enter your current password again", vbOKOnly, "Incorrect Password"
End If
End Sub


When users try change their password (successfully), a message box pops up with "You are about to update 1 row". After clicking ok, the record in the table is changed into the new record. Also note the three password textboxes have a password mask.

Heres the problems:

1. After changing the password, even though the new password has now been inputted into the table, the user can NOT login using the new password. (I suspect the problem in with the mask. If so, how do I get rid of the problem and still keep the mask)

2. How can i get rid of the error default message "you are about to update 1 row" and replace it with "Password Changed" message?
 

Mr. B

"Doctor Access"
Local time
Today, 15:55
Joined
May 20, 2009
Messages
1,932
For your issue #2, the message you are seeing is actually a "warning" message. To stop seeing that message, just prior to the code where you are updating the record use the following statement:

You have a couple of options:

Option one is to turn the warning messaging off while you do the update:
Code:
Me.txtNewPw.SetFocus
Dim strSQL As String
strSQL = "UPDATE tblLogin SET Password = '" & Me.txtNewPw.Text & "' WHERE ID = txtLoginID"
Docmd.SetWarnings False
DoCmd.RunSQL strSQL
Docmd.SetWarnings True
MsgBox "Password Changed"

Option two is to use a different method for reunning your SQL statement:
Code:
Me.txtNewPw.SetFocus
Dim strSQL As String
strSQL = "UPDATE tblLogin SET Password = '" & Me.txtNewPw.Text & "' WHERE ID = txtLoginID"
Currentdb.Execute strSQL
MsgBox "Password Changed"

Your issue #1 is a different matter. What method are you using to determine if the user's password is correct? Can you post your code for this?
 

NigelShaw

Registered User.
Local time
Today, 21:55
Joined
Jan 11, 2008
Messages
1,573
Hey,

I have a form which I have used for users to login to the database. This form works well, but i also added a "change your password form".

This form has a combo box which has the user name and three other text boxs (txtOldPW, txtNewPW, txtNewPW2). It also has a change password button too (btnChangedPW).

I have also added a onclick code to the button:

Private Sub btnChangedPw_Click()
Dim PWtocompare As String
PWtocompare = DLookup("Password", "tblLogin", "[ID]=" & Me.txtLoginID.Value)
If txtOldPw = PWtocompare Then
If txtNewPw = TxtNewPw2 Then

Me.txtNewPw.SetFocus
Dim strSQL As String
strSQL = "UPDATE tblLogin SET Password = '" & Me.txtNewPw.Text & "' WHERE ID = txtLoginID"
DoCmd.RunSQL strSQL

Else
MsgBox "Passwords do not match, please re-enter your new password", vbOKOnly, "Passwords do not match"
End If
Else
MsgBox "Current password does not match records. Please enter your current password again", vbOKOnly, "Incorrect Password"
End If
End Sub


When users try change their password (successfully), a message box pops up with "You are about to update 1 row". After clicking ok, the record in the table is changed into the new record. Also note the three password textboxes have a password mask.

Heres the problems:

1. After changing the password, even though the new password has now been inputted into the table, the user can NOT login using the new password. (I suspect the problem in with the mask. If so, how do I get rid of the problem and still keep the mask)

2. How can i get rid of the error default message "you are about to update 1 row" and replace it with "Password Changed" message?

Hi,

as a point really. There doesnt seem to be any strict password comparing. If your password was "password" then Password , PaSsWoRd, paSSWorD will all get you in when it shouldn't.


cheers

N
 

SShafeeq

Registered User.
Local time
Tomorrow, 00:55
Joined
Jan 4, 2011
Messages
32
Thanks Mr.B, the second problem has been solve. NigelShaw, i dont want passwords to be case sensitive so thats ok.

Now for the first issue, which is the most pressing...

I am using the code:

Private Sub Command10_Click()
If IsNull(Me.txtLoginID) Or Me.txtLoginID = "" Then
MsgBox "Please enter your username.", vbOKOnly, "Required Data"
Me.txtLoginID.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPasswordBox) Or Me.txtPasswordBox = "" Then
MsgBox "Please enter your password", vbOKOnly, "Required Data"
Me.txtPasswordBox.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this matches value chosen in combo box
If Me.txtPasswordBox.Value = DLookup("Password", "tblLogin", "[ID]=" & Me.txtLoginID.Value) Then
Username = Me.txtLoginID.Value
'Close logon form and open splash screen

DoCmd.OpenForm "MainMenu"
Else
MsgBox "Incorrect Password. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPasswordBox.SetFocus
End If

End Sub
 

DCrake

Remembered
Local time
Today, 21:55
Joined
Jun 8, 2005
Messages
8,632
Here is a link to a sample mdb that might give you what you want.
 

SShafeeq

Registered User.
Local time
Tomorrow, 00:55
Joined
Jan 4, 2011
Messages
32
Hey DCrake thanks but this doesnt help me as there are no forms in your database, which is where my coding is.
 

Mr. B

"Doctor Access"
Local time
Today, 15:55
Joined
May 20, 2009
Messages
1,932
I assume that your login form is unbound. If this is the case then try changing the statement:

Me.txtPasswordBox.Value

to

Me.txtPasswordBox.Text

and see if that changes the result.

Also change the references to the value in your conditional statment to refer to the Text property.
 

DCrake

Remembered
Local time
Today, 21:55
Joined
Jun 8, 2005
Messages
8,632
There are forms it is just that you have neglected to change the layout of the navigation pane to show all object groups.
 

Mr. B

"Doctor Access"
Local time
Today, 15:55
Joined
May 20, 2009
Messages
1,932
Just FYI, the reason that changing the reference to your controls from .value to .text made the difference is that you are using an unbound form.

I appreciate your followup post of Thanks, but if you don't mind, click the "Thanks" button at the lower right corner.

Good luck with your project.
 

Users who are viewing this thread

Top Bottom