Jump to content

Password Complexity.. regular expression


EndFunc
 Share

Recommended Posts

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.
Link to comment
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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...