Inforcing a password criteria? (1 Viewer)

MehItsMe

New member
Local time
Yesterday, 17:25
Joined
Mar 29, 2009
Messages
1
Hey all.
I'm developing a system that is password protected; one of the functions that is required is that the user is able to change there password on the condition that it meets the password criteria.
The user needs to have a password consisting of at least 8 chars which must include a letter, a upper case letter and a number.
I have code that handles the changing of the password, however I was wondering if anyone could give me any pointers as to how I would be able to inforce the above criteria.
I've done some searching and the only way that I can see of doing this is to store each letter that the user enters into an array and then do a for loop to test each of the charactas, although to be completely honest i'm very new to programming in vba.
If anyone could link me to some sample code that I could adapt to fit my needs I would be very greatfull.
Thanks for reading.
 

rapsr59

Registered User.
Local time
Yesterday, 18:25
Joined
Dec 5, 2007
Messages
93
You might try this.

In the After Update event of the control that contains the entered password:

Code:
    Dim t As Integer
    Dim blnNumber As Boolean
    Dim blnLCaseLetter As Boolean
    Dim blnUCaseLetter As Boolean
 
    'Check Length
    If Len(txtPassword) < 8 Then
        MsgBox "Please Enter A Pass Word That " & _
        "Contains At Least 8 Characters!"
        Exit Sub
    End If
 
    'Correct number of characters >= 8
    For t = 1 To Len(txtPassword)
 
        'Check for Upper case letter
        If Asc(Mid(txtPassword, t, 1)) >= 65 _
        And Asc(Mid(txtPassword, t, 1)) <= 90 Then
            blnUCaseLetter = True
        End If
 
 
        'Check for Lower Case letter
        If Asc(Mid(txtPassword, t, 1)) >= 97 And _
        Asc(Mid(txtPassword, t, 1)) <= 122 Then
            blnLCaseLetter = True
        End If
 
        'Check for number
        If Asc(Mid(txtPassword, t, 1)) >= 49 And _
        Asc(Mid(txtPassword, t, 1)) <= 57 Then
            blnNumber = True
        End If
 
 
    Next t
 
    If blnUCaseLetter And blnLCaseLetter And blnNumber Then
        MsgBox "Password OK!"
        Exit Sub
    Else
        MsgBox "Please Enter A Password That Contains " & _
        "At Least 8 Characters and Contains " & _
        "1 Upper Case Alfa Character, " & _
        "1 Lower Case Alfa Character, " & _
        "and 1 Numeric Character!" & Chr(13) & "Please Re-Enter Password"
    End If

Regards, Richard

You might want to place the above code in the controls BeforeUpdate event and the cursor will stay in the Password field.

Play with it and use the best method that accomplishes what you need for your application.
 
Last edited:

Users who are viewing this thread

Top Bottom