VB6 Password with expiration date

Hi ,Do I need to know if possible to find a project with sample for include or modify my VB application with password expiration date (and forcing the user to change the password saved in DB when the expiration date is reached, and must be obviously different, I am using VB6 and Access 2K with ADO 2.7 ( no DataControl)? In my project this function  check the user login, how may I change the code for include the expiration date in this Function (and suggest the password change to user when reach the expiration date)????

Function sample follow:

===============================0

Function ControllaUtente() As Integer
    Dim Sql As String
    ControllaUtente = True  'utente ok
    UtenteAmministratore = False
    NomeUtente = ""
    If txtUserName.Text = "ADMIN" And txtPassWord.Text = "ADMIN" Then
        UtenteAmministratore = True 'se utente Amministratore(ADMIN) esce dalla funzione
        'senza effettuare il ControlloAccesso abilitando così tutti i menu
        Exit Function
    End If
    'On Error GoTo ErroreUtenti
    Set rsUtenti = New ADODB.Recordset
    Sql = "select * from tblUtenti where IDUtente='" & txtUserName & "'"
    rsUtenti.Open Sql, cn, adOpenDynamic, adLockOptimistic
    If rsUtenti.EOF Then
        ControllaUtente = False
        rsUtenti.Close
        Set rsUtenti = Nothing
        Exit Function
    End If
    '
    If rsUtenti("IDUtente") <> txtUserName.Text Then
            ControllaUtente = False
                Else
            If rsUtenti("PassW") = txtPassWord.Text Then
                UtenteAmministratore = rsUtenti!Amministratore
                NomeUtente = rsUtenti!Nominativo
                    PercorsoImgAttuale = "" & rsUtenti!PercorsoImg
                    'controlla la data della password e propone l'aggiornamento della stessa
                    'If DateDiff("d", rsUtenti!DataAggPsw, Now) >= 30 Or IsNull(rsUtenti!DataAggPsw) Then =====> here is the code for expiration
date
                       'Stop
                       'MsgBox "ATTENZIONE Login Password scaduta, reinserire NUOVA PASSWORD", vbInformation
                       'Stop
                       'If ControllaPassword = False Then
                      'Stop
                    'End If
                       ControllaAccesso 'controlla i menu attivi per utente
                   'Else
                ControllaUtente = True
                'Stop
                'End If
            End If
    End If
    rsUtenti.Close
    Set rsUtenti = Nothing
    Exit Function
ErroreUtenti:
    MsgBox "errore"
    VisualizzaADOError cn
    Exit Function
End Function





Regards:


Massimo
Joice64Asked:
Who is Participating?
 
jkaiosIT DirectorCommented:
... correction to the 'strSQL' line ...

strSQL = "SELECT * FROM tblUsers WHERE sUserID = '" & sUserName & "'"

The "sUserName" is the function argument variable, and not 'sUser' or you can just change the "sUserName" argument to just sUser
0
 
jkaiosIT DirectorCommented:
Assuming that you have a table called "tblUsers" that contains all usernames and passwords.
The table has the following fields:

  sUserID       - Text field
  sPassword   - Text field
  dateExpired  - Date field

======================================================================================
Private Sub Command1_Click()

  If Login(txtUserName, txtPassword) Then
    'Display the Data Maintenance form
    frmEdit.Show
  Else
    Msgbox "Invalid username or bad password, pls try again!", vbInformation
  End If

End Sub

-----------------------------------------------------------------------------------------------------------------------------------------------------------
Public Function Login(sUser As String, sPass As String) As Boolean

  Dim rsUser As New ADODB.Recordset
  Dim strSQL As String

  strSQL = "SELECT * FROM tblUsers WHERE sUserID = '" & sUser & "'"
  rsUser.Open myConnection, strSQL
  If rsUser.EOF Then           '// Invalid Username
     Login = False
     Exit Function
  Else                                '// Validate the password
     If rsUser("sPassword") = sPass Then
        'Check password expiration date
        If rsUser("dateExpired") <= Date Then
           MsgBox "You password is expired, you must change it now!"
           Login = ChangePassword(sUser)      '<---Call to another sub-routine to change the user's password. This routine returns a Boolean
        Else
           Login = True          '// Login successful
        End If
     Else
        Login = False            '// Invalid password
     End If
  End If

End Function
======================================================================================
0
 
Joice64Author Commented:
Hi, may you include for complete the sub routine for change the password in this function sample?


thanks again


Regards:


Massimo
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Joice64Author Commented:
I have forgotten in previous comment, I need to update the rsUser("dateExpired"), and the user must change the password again( after e.g 90 or 120 days again) when the user update the password too.


thanks again for your help


regard:

Massimo DELLI CARRI
0
 
jkaiosIT DirectorCommented:
In your ChangePassword() sub-routine, your codes to update the "dateExpired" field would look similar to this:

Public Function ChangePassword(sUserName As String) As Boolean
  Dim rsUser As New ADODB.Recordset
  Dim strSQL As String

  strSQL = "SELECT * FROM tblUsers WHERE sUserID = '" & sUser & "'"
  rsUser.Open myConnection, strSQL
  If rsUser.EOF Then           '// Invalid Username
     ChangePassword = False
     Exit Function
  Else                                '// Add 90 days from today (e.g., if the current date is 05/11/2006, the DateAdd function will return 08/09/2006
     rsUser("dateExpired") = DateAdd("d", 90, Date)
     rsUser.Update
     ChangePassword = True
  End If
End Function
0
 
Joice64Author Commented:
Hi, is not clear for me  how may I change the password when expired if the lofin form is already open with these sub routine?



regards:

Massimo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.