?
Solved

VB6 Password with expiration date

Posted on 2006-05-09
6
Medium Priority
?
1,474 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:Joice64
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:jkaios
ID: 16647191
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
 

Author Comment

by:Joice64
ID: 16647622
Hi, may you include for complete the sub routine for change the password in this function sample?


thanks again


Regards:


Massimo
0
 

Author Comment

by:Joice64
ID: 16648802
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:jkaios
ID: 16653086
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
 
LVL 12

Accepted Solution

by:
jkaios earned 400 total points
ID: 16653176
... 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
 

Author Comment

by:Joice64
ID: 16673867
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question