|
-
September 19th, 2001, 01:09 PM
#1
Compare Str to Rules
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
-
September 19th, 2001, 02:00 PM
#2
Re: Compare Str to Rules
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
[email protected]
-
September 19th, 2001, 04:34 PM
#3
Re: Compare Str to Rules
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|