Click to See Complete Forum and Search --> : Compare Str to Rules


Loch
September 19th, 2001, 01:09 PM
I am working on a password comparison tool.
My question revolves around comparing if specific rules were met with password.
The rules are
1 PSWD Str Length greater then 6 less then 20
-Solved with Len() function
2 PSWD must contain at least one number key and
one special key i.e. !@#$%^&*()
my question regards the second rule.

How do I compare a Str to ensure it contains at least one number and one special key?
any help would be appreciated
Thanks

Iouri
September 19th, 2001, 02:00 PM
Use this fast function to test for the occurrence of nonalphanumeric characters in a string:

Private Declare Function StrSpn Lib "SHLWAPI" Alias _
"StrSpnW" (ByVal psz As Long, ByVal pszSet As Long) As Long

Public Function IsAlphaNum(ByVal sString As String) As Boolean
Dim lPos As Long

Const ALPHA_NUM As String = "abcdefgihjklmnopqrstuvwxyz" & _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

' Returns the first occurrence of nonmatching characters
lPos = StrSpn(StrPtr(pString), StrPtr(pAlphaNum))
' If the return position is not equal to the length of the
' input string, nonalphanumeric chars were found.
IsAlphaNum = (lPos = Len(sString))
End Function

You can easily modify this function to scan for invalid characters by editing the ALPHA_NUM constant so it
includes only characters you consider legal.


Iouri Boutchkine
iouri@hotsheet.com

Drew A
September 19th, 2001, 04:34 PM
Another method would be to get the Len on the password and then merely go through each position on the string and compare it to your ASCII code values that are acceptable for the special keys and then another loop to check for the number key.

Dim Length as Integer
Length = len(string)
for i = 1 to len(string)
Asc(mid(string, i, 1)) = (Your ASCII Codes)
next i