User Change Password

writer2000

Registered User.
Local time
Yesterday, 22:55
Joined
Jun 16, 2015
Messages
20
So I have a login system established with loginID, passwords, and different user types. I also have a User Change Password form. However, this form only allows the user to change their password to something new. Also, for some reason the form only allows the first user in the table (ID#1) to be changed regardless of who is logged in. I was using an embedded Macro, but this is probably a horrible idea. I need to be able to have the old password entered and verified before the password can be changed to something new. Thank you for your help!
 
To get help you need to provide the bits you have - the code. Otherwise it's just digital armwaving - impressive but ineffective :D
 
Let's see, on the change user password form has just the simple embedded Marco (save prompt). It is linked to my user table (it stores the loginID, password, and usertype).

The following code is set for when you hit Ok on the Login Form:

Option Compare Database

Private i As Integer

Private Const maxi As Long = 0

Private Sub Command1_Click()
Dim User As String
Dim AccessLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim WorkerName As String
Dim TempLoginID As TempVar
Dim DepartmentID As Integer
Static i As Integer

If IsNull(Me.txtUserName) Then
MsgBox "Please Enter LoginID", vbInformation, "LoginID Required"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup("LoginID", "tblworker", "LoginID = '" & Me.txtUserName.Value & "' And password = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid LoginID or Password!"
i = i + 1
If (i = 3) Then
MsgBox "Maximum # of Attempts Reached. Contact Database Administrator.", vbOKOnly
DoCmd.Quit
End If
Else
TempVars!TempLoginID = Me.txtUserName.Value
WorkerName = DLookup("[workername]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[password]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")
ID = DLookup("[workerid]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")
AccessLevel = DLookup("[UserType]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")

Dim stDocName As String
DoCmd.SetWarnings False
stDocName = "qryLogInTimes"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True

If Not IsNull(DLookup("[Deptname]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")) Then
DepartmentID = DLookup("[Deptname]", "tblworker", "[LoginID] = '" & Me.txtUserName.Value & "'")
End If
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please Change Password", vbInformation, "New Password Required"
DoCmd.OpenForm "frmworkerinfo", , , "[workerid] = " & ID
Else
DoCmd.OpenForm "NavigationF"
Forms![NavigationF]![txtLogin] = TempVars!TempLoginID
Forms![NavigationF]![txtUser] = WorkerName
Forms![NavigationF]![txtSecurity] = AccessLevel
'call security level from sub function below
Call Security(AccessLevel, DepartmentID)

End If
End If
End If
End Sub
 
I don't have a query yet. So I am assuming I need to make a query that checks the LoginID and the Password. I am not 100% certain on the exact coding I need to write after that though. Here is the code I have for the change user password form:

Private Sub Command178_Click()
On Error GoTo Err_Command6_Click
Dim intUserID As Integer
Dim strOldPassword As String
Dim strSQL As String

intUserID = Me.List0
strOldPassword = DLookup("[Password]", "tblworker", "[LoginID]=" & intUserID)
Select Case strOldPassword
Case Is = Me.TextBox2
strSQL = "UPDATE tblworker_details SET Password=" & "'" & Me.TextBox2 & "'" & " " & "WHERE LoginID=" & "'" & Me.List0 & "';"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "Password has been changed", vbInformation, "Password Changed"
Case Is <> Me.TextBox2
MsgBox "The Old Password doesnot match", vbInformation, "Type Correct Old Password"
End Select

Exit_Command6_Click:
Exit Sub

Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click

End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom