How to change password every 30 days in your ms access login form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • elenaA
    New Member
    • Aug 2016
    • 42

    How to change password every 30 days in your ms access login form

    Hello

    I have my own login form. To enter into db user must enter his user name and password. Now I want to make that user must change the password if passess 30 days since he last time change his password.

    How Can i do that?
    thank you




    here is my code

    Option Compare Database

    Private Sub Command1_Click( )
    Dim UserName, Temppass As String
    Dim UserLevel, ID As Integer
    Dim TempLogin As TempVar

    If IsNull(Me.txtLo ginID) Then
    MsgBox "Please enter UserID", vbInformation, "UserID requeired"
    Me.txtLoginID.S etFocus
    ElseIf IsNull(Me.txtPa ssword) Then
    MsgBox "Please enter Password", vbInformation, "Password requeired"
    Me.txtPassword. SetFocus
    Else
    If (IsNull(DLookup ("UserID", "tblUser", "UserLogin = '" & Me.txtLoginID.V alue & "' And password = '" & Me.txtPassword. Value & "'"))) Then
    MsgBox "Invalid LoginID or Password!"
    Else
    TempVars!TempLo gin = Me.txtLoginID.V alue

    UserName = DLookup("[Username]", "tblUser", "[UserLogin] = '" & Me.txtLoginID.V alue & "'")
    UserLevel = DLookup("[UserSecurity]", "tbluser", "[UserLogin] = '" & Me.txtLoginID.V alue & "'")
    Temppass = DLookup("[password]", "tblUser", "[UserLogin] = '" & Me.txtLoginID.V alue & "'")
    ID = DLookup("[Userid]", "tblUser", "[UserLogin] = '" & Me.txtLoginID.V alue & "'")
    'DoCmd.Close
    If (Temppass = "password") Then
    DoCmd.Close
    MsgBox "Please change Password", vbInformation, "New password requeired"
    DoCmd.OpenForm "ChangePassword ", , , "[Userid] = " & ID
    ElseIf IsNull(DLookup( "answer1", "tblUser", "UserLogin = '" & Me.txtLoginID.V alue & "'")) Or IsNull(DLookup( "answer2", "tblUser", "UserLogin = '" & Me.txtLoginID.V alue & "'")) Or IsNull(DLookup( "answer3", "tblUser", "UserLogin = '" & Me.txtLoginID.V alue & "'")) Then
    DoCmd.Close
    Msg = "Your security questions have not been set up. " _
    & vbCr & "Do you want to set it up now?"
    Style = vbYesNo + vbQuestion
    Title = "Set Up Security Question?"
    Response = MsgBox(Msg, Style, Title)
    If Response = vbYes Then
    DoCmd.OpenForm "ChangePassword ", , , "UserID =" & ID
    Exit Sub
    End If
    If Response = vbNo Then
    'open different form according to user level
    If UserLevel = 1 Then ' for admin
    DoCmd.ShowToolb ar "Ribbon", acToolbarYes
    DoCmd.OpenForm "GlavniMeni "
    Forms![GlavniMeni]!poljeAdminForm .Visible = True
    Else
    DoCmd.ShowToolb ar "Ribbon", acToolbarNo
    DoCmd.OpenForm "GlavniMeni "
    Forms![GlavniMeni]!poljeAdminForm .Visible = False
    End If
    End If
    Else
    DoCmd.Close
    'open different form according to user level
    If UserLevel = 1 Then ' for admin
    DoCmd.ShowToolb ar "Ribbon", acToolbarYes
    DoCmd.OpenForm "GlavniMeni "
    Forms![GlavniMeni]!poljeAdminForm .Visible = True

    Else
    DoCmd.ShowToolb ar "Ribbon", acToolbarNo
    DoCmd.OpenForm "GlavniMeni "
    Forms![GlavniMeni]!poljeAdminForm .Visible = False

    End If
    End If
    End If
    End If
    End Sub
  • cactusdata
    Recognized Expert New Member
    • Aug 2007
    • 223

    #2
    Whenever the password is changed, record that in a field in tblUser:

    Code:
    LastChangedPassword.Value = Now
    During login, check the days passed since the last change of password:

    Code:
    If DateDiff("d", LastChangedPassword, Now) > 30 Then
        ' Call form to change the password.
    End If

    Comment

    • elenaA
      New Member
      • Aug 2016
      • 42

      #3
      Where in my code for login procedure I have to put that?

      If DateDiff("d", LastChangedPass word, Now) > 30 Then
      ' Call form to change the password.
      End If

      I make field in tblUser (LastChangedPas sword, date/time, =now()?

      did i make this correct?
      thanks

      Comment

      • cactusdata
        Recognized Expert New Member
        • Aug 2007
        • 223

        #4
        It's up to you where to modify your code to perform the check. It's only you who knows how the login procedure should run.

        The field data type is correct.

        Comment

        • elenaA
          New Member
          • Aug 2016
          • 42

          #5
          Yes I understand,
          I want to put this when user try to login
          where do you suggest me is best to put it? i am quite new in vba programing...
          thank you
          can you give me example so i will try
          thanks

          Comment

          • cactusdata
            Recognized Expert New Member
            • Aug 2007
            • 223

            #6
            It's difficult to read your code, and I don't have the forms.

            Make the check after successful login. Then call the form to change password if the checks tells to do so. That should be it.

            Comment

            • elenaA
              New Member
              • Aug 2016
              • 42

              #7
              Ok I will try to make this working
              thank you

              Comment

              Working...