Sign in to follow this  
Followers 0
EndFunc

Password Complexity.. regular expression

4 posts in this topic

#1 ·  Posted (edited)

Ok so i've used some samples I found on the forum to help create me a password complexity checker.

Now, problem is I want to be able to allow either a number OR a symbol. However the script keeps requiring both. What am I doing wrong?

Here is a snippet of the code where it does it. The line with the OR in it close to the bottom.

Func CheckPWD()
If StringRegExp($passwd,'[a-z]') = "0"  Then                            ;// [verified] at least one lower case letter
    Msgbox(16, $AppName, $Error_Message, 10)
        GUICtrlSetData($Password, "")
    GUICtrlSetData($Confirm, "")
    WinActivate("Set Account Password")
    GUICtrlSetState($Password, $GUI_FOCUS)
    SetError(1)
    Return
    ElseIf StringRegExp($passwd,'[A-Z]') = "0" Then              ; // [verified] at least one upper case letter
    Msgbox(16, $AppName, $Error_Message, 10)
        GUICtrlSetData($Password, "")
    GUICtrlSetData($Confirm, "")
    WinActivate("Set Account Password")
    GUICtrlSetState($Password, $GUI_FOCUS)
    SetError(1)
    Return
    ElseIf StringRegExp($passwd,'\d+') = "0" OR StringRegExp($passwd,'[!,@,#,$,%,^,&,*,?,_,~]') = "0" Then ;// [verified] at least one number
    Msgbox(16, $AppName, $Error_Message, 10)
    GUICtrlSetData($Password, "")
    GUICtrlSetData($Confirm, "")
        WinActivate("Set Account Password")
    GUICtrlSetState($Password, $GUI_FOCUS)
    SetError(1)
    Return
EndFunc
Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites



Maybe using And:

Local $passwd = "!1aA", $AppName = "AppName", $Error_Message = "Weak"

CheckPWD()

Func CheckPWD()
    If StringRegExp($passwd,'[a-z]') = 0  Then                            ;// [verified] at least one lower case letter
        
        Msgbox(16, $AppName, $Error_Message, 10)
        Return SetError(1)
        
    ElseIf StringRegExp($passwd,'[A-Z]') = 0 Then              ; // [verified] at least one upper case letter
        
        Msgbox(16, $AppName, $Error_Message, 10)
        Return SetError(1)
        
    ElseIf StringRegExp($passwd,'\d+') = 0 And StringRegExp($passwd,'[!@#$%^&*?_,~]') = 0 Then ;// [verified] at least one number
        
        Msgbox(16, $AppName, $Error_Message, 10)
        Return SetError(1)
    Else
        
        MsgBox(0x30, $AppName, "Nice", 10)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

And another example without "And" or "Or".

Local $passwd = "aB3"

MsgBox(0, "AppName", CheckPWD($passwd), 8)

Func CheckPWD($passwd)
    Local $Error_Message = ""
    If StringRegExp($passwd, '[a-z]') = 0 Then $Error_Message = "At least one lower case letter missing" & @CRLF ;// [verified] at least one lower case letter
    If StringRegExp($passwd, '[A-Z]') = 0 Then $Error_Message &= "At least one upper case letter missing" & @CRLF ; // [verified] at least one upper case letter
    If StringRegExp($passwd, '[!@#$%^&*?_,~\d]') = 0 Then $Error_Message &= "At least one number or symbol missing" & @CRLF;// [verified] at least one number
    If $Error_Message = "" Then $Error_Message = "Password acceptable"
    Return $Error_Message
EndFunc ;==>CheckPWD

Edit: Changed '[!,@,#,$,%,^,&,*,?,_,~\d]' to '[!@#$%^&*?_,~\d]'. One coma within square brackets is enough.

Edited by Malkey

Share this post


Link to post
Share on other sites

Thanks both. Seems so simple now. lol. I didn't know you could combine them as well. Nice.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0