Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Password - Number of attempts (97/2k)

    I am trying to figure out the code which would allow a user three attempts at a password and if still incorrect, an action is invoked.
    The textbox requiring the password is on a form. It has no buttons as yet.
    Help please.

    Rob
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Password - Number of attempts (97/2k)

    Hi Rob,

    I don't have time to work out an example for you now <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>. Have a look at ACC2000: How to Create a Password Protected Form or Report. It shouldn't be too hard to add a variable intNumberOfAttempts to the sample code given there, increment it each time a password is evaluated and do whatever you deem necessary when a predetermined count is reached.

  3. #3
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Password - Number of attempts (97/2k)

    Rob,

    Here is the code I use. You will notice a CMD5 Type, that is an MD5 Hashing Class module. I store my passwords using the MD5 hashing algorythm in the db and not plaintext. MD5 is a one way algorythm.

    The key component is the Static declaration for intTries. Static keeps the value across separate "runs" of the code.

    A couple of other notes:

    gcintLOGINATTEMPTS is a global constant that defines the number of login attempts since I needed a way to quickly change the number of attempts. IIRC, if you set this value to a negative number, then you can an unlimited number of attempts.

    <pre>Private Sub cmdOK_Click()
    '--------------------------------------------------------------------------
    '.Purpose : To handle the OK button Click event and
    '. verify login information
    '.Author : Bryan Carbonnell
    '.Date : 18-Oct-2002
    '.Revised : 18-Oct-2002 - Original
    '--------------------------------------------------------------------------
    Const cstrProcName As String = "cmdOK_Click"
    Static intTries As Integer
    Dim strSQL As String
    Dim rst As DAO.Recordset
    Dim md5 As CMD5
    Dim strMsg As String

    'Build SQL String
    strSQL = "SELECT * FROM tblUser " & _
    "WHERE UserName ='" & txtUserName & "'"
    'Open RecordSet
    Set rst = CurrentDb().OpenRecordset(strSQL)

    If rst.BOF = True And rst.EOF = True Then
    'No records, so we have an invalid UserName
    intTries = intTries + 1
    mbolValidLogin = False
    Else
    'Valid UserName, now we need to check the password
    Set md5 = New CMD5
    If md5.md5(txtPassword & "") <> rst!fldPassword Then
    'Invalid Password
    intTries = intTries + 1
    mbolValidLogin = False
    Else
    mbolValidLogin = True
    gstrUserName = txtUserName
    End If
    End If

    If intTries >= gcintLOGINATTEMPTS And gcintLOGINATTEMPTS > 0Then
    'Too many tries, so boot the user
    strMsg = "You have exceeded the maximum number of Login attempts." _
    & vbCrLf & "" _
    & vbCrLf & "Please contact the Systems Administrator if you continue" _
    & vbCrLf & "having problems logging in." _
    & vbCrLf & "" _
    & vbCrLf & "The application will now shut down."
    'Display message box
    MsgBox strMsg, vbCritical + vbOKOnly, "Login Failure"
    '
    Application.Quit
    Else
    Select Case Me.ValidLogin
    Case False
    'Invalid Login
    strMsg = "Invalid User Name or Password entered." & vbCrLf & vbCrLf & _
    "Click OK to try again. Clcik Cancel to Exit Application."

    If MsgBox(strMsg, vbOKCancel + vbExclamation, "Invalid Login") = vbCancel Then
    Application.Quit
    End If
    Case True
    'Valid Login
    Me.Visible = False
    End Select
    End If
    End Sub</pre>

    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  4. #4
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Password - Number of attempts (97/2k)

    Thanks Hans. I've downloaded the code and I'm working my way through it.

    Regards

    Rob
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

  5. #5
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Password - Number of attempts (97/2k)

    Thanks Bryan. I'm trying to get my head around two sets of code. I'm still a relative beginner wrt Access. The exercise will do me good. I'll get back if I experience difficulties.

    Best Wishes

    Rob
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

  6. #6
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Password - Number of attempts (97/2k)

    Please do get back if you have questions.

    It's not one of my more commented "public" procedures.

    I just ripped it right out of one of my apps.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Password - Number of attempts (97/2k)

    MD5 Hashing Class module.
    Is this one of the inner functions of Access?
    Pat <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Password - Number of attempts (97/2k)

    I wish! <img src=/S/disappointed.gif border=0 alt=disappointed width=15 height=15>
    Charlotte

  9. #9
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Password - Number of attempts (97/2k)

    Pat,

    No it's not. It's a class module I got off the web from http://www.frez.co.uk/freecode.htm

    I took the VB version and imported it into Access and everything was fine.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  10. #10
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Password - Number of attempts (97/2k)

    Thanks Bryan

    That will prove useful.

    Pat <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •