Solved Change password using tempvar not passing to following form

donkey9972

Registered User.
Local time
Today, 09:12
Joined
May 18, 2008
Messages
54
Okay I have a login form and when the temporary password is set to "Password" for a new user, the new user logs in and then it should direct them to change their password upon first login. So on the login form I have this code set on the login button:

Code:
Private Sub cmd_login_Click()
Dim FIRST_NAME As Variant, access_level As Variant, user As Variant
Dim TempPass As String

If Trim(Me.txt_username.Value & vbNullString) = vbNullString Then
    MsgBox prompt:="Username required.", buttons:=vbExclamation, title:="Information"
    Me.txt_username.SetFocus
Exit Sub
End If

If Trim(Me.txt_password.Value & vbNullString) = vbNullString Then
    MsgBox prompt:="Password required.", buttons:=vbExclamation, title:="Information"
    Me.txt_password.SetFocus
Exit Sub
End If

' RETREIVE FROM SAVED QUERY
' ASSUMES EVERY USER GIVEN A NON-NULL ACCESS LEVEL
FIRST_NAME = DLookup("FirstName", "tbl_login", "UserName = '" & Me.txt_username & "' and password = '" & Me.txt_password & "'")
access_level = DLookup("access_level", "tbl_login", "UserName = '" & Me.txt_username & "' and password = '" & Me.txt_password & "'")

If IsNull(FIRST_NAME) = True Then
    MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, title:="Information"
    Me.txt_username.SetFocus
Else
    MsgBox prompt:="Welcome, " & FIRST_NAME & ".", buttons:=vbOKOnly, title:="to the QAE System"

TempPass = DLookup("[Password]", "tbl_Login", "UserName='" & Me.txt_username.Value & "'")
    If (TempPass = "Password") Then
        DoCmd.OpenForm "frm_ChangePassword", acNormal, "", "", , acWindowNormal
        GoTo Done
    End If
  
'save the first_name and access_level to Tempvars
TempVars("First_Name") = FIRST_NAME
TempVars("Access_Level") = access_level
TempVars("user") = Me.txt_username.Value
  
' CONDITIONALLY OPEN FORMS
Select Case access_level
Case "Admin"
    DoCmd.OpenForm "frm_Admin"
    DoCmd.Close acForm, "frm_login", acSaveNo
        

Case "User"
    DoCmd.OpenForm "frm_User"
    DoCmd.Close acForm, "frm_login", acSaveNo
End Select
End If
Done:
    DoCmd.Close acForm, "frm_login", acSaveNo
End Sub

When a user logs in with user name and password if their password is set to anything other than "Password" it displays their first name correctly on the following form. This code is on that following form and it works really well:

Code:
Private Sub Form_Load()
    Me.Text325 = TempVars("First_Name").Value & ""
End Sub

I also have a button on that form if the user wants to change their password and the First name carries over without an issue. However, my problem is when their password is set to "Password" requiring a first time login password change it is not displaying. This is the code on that password change form:

Code:
Private Sub Form_Load()
    Me.Text337 = TempVars("First_Name").Value & ""
End Sub
 
In the case that the password is set to "password" do you have a guarantee that there IS a first name? How so?

If this person IS in the login table, then it LOOKS like they WILL have a record with the username, usage level, and either the actual password or the literal word "password" in the password slot. In a legit "forced login" case I could see things getting properly loaded. However, is this something that happens when a user first logs in after, say, a system reboot? Because TempVars aren't permanent... they are not defined in a session until someone defines them.

Unless there is some action in the Form_Open routine that relates to loading the TempVars objects, a login to a freshly reloaded application isn't guaranteed to have ANYTHING in TempVars at Form_Load time. I would do a step-by-step trace of the code starting from the app's opening form and whatever it does to the TempVars object, all the way to the point where that particular Form_Load fails to find the value in TempVars.
 
When changing your temp password your code proceeds to Done before setting the username.

Adjust the order of processing a bit:
Code:
' ...
TempPass = DLookup("[Password]", "tbl_Login", "UserName='" & Me.txt_username.Value & "'")
 
'save the first_name and access_level to Tempvars
TempVars("First_Name") = FIRST_NAME
TempVars("Access_Level") = access_level
TempVars("user") = Me.txt_username.Value

    If (TempPass = "Password") Then
        DoCmd.OpenForm "frm_ChangePassword", acNormal, "", "", , acWindowNormal
        GoTo Done
    End If

' ...

(I hope this login form is not for anything other than cosmetic purpose, as it is very insecure)
 
Yes that seemed to fix my problem. Thank you for pointing that out for me cheekybuddha. And yes this is mostly for cosmetics.
 

Users who are viewing this thread

Back
Top Bottom