Mat Posted April 13, 2009 Posted April 13, 2009 (edited) In a thread in H+S a guy asked for a password input box with a degree of complexity.see that hereI just expanded on what I already had and got this script (added in password enter just to be complete)Complexity can be a mixture of: 0 - No complexity 1 - Confirm 2 - Mandatory entry 4 - 8 letters min 8 - Numbers must be included 16 - Capitals must be includedVery basic, but it works.; Functions; * _PasswordCreate; * _PasswordEnter; * _PasswordCheck; * _PasswordCheckExt - Wide Boy Dixon; * _PasswordCreateExt - Wide Boy DixonIt's late, I garuantee errors..please point out...PasswordUDF.au3I also think some people might have done this before, but ah well.MDiesel Edited April 15, 2009 by mdiesel AutoIt Project Listing
GEOSoft Posted April 14, 2009 Posted April 14, 2009 Check the other thread for another concept. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Mat Posted April 14, 2009 Author Posted April 14, 2009 (edited) Yep, I'm writing a reply to that at the moment....but I wont, I'll post it here instead, just to stop stupid amounts of double posting.GeoSofts script:CODEGlobal $sPass$sUserPass = _PassWord()If @Error Then MsgBox(0, "Error " & @Error, "No Password")Else MsgBox(0, "Results", $sUserPass)EndIfFunc _Password()$sPass = ""$sPass = InputBox("Password", "Please enter your password", "", "*")If $sPass Then If StringLen($sPass) >= 8 Then $iValid = 0 For $i = 1 To 3 $iValid += _Check($i) Next ;MsgBox(0, "TEST", $iValid) If $iValid <3 Then _Error() _Password() Else $sVerify = InputBox("Confirm Password", "Please enter your password again", "", "*") If NOT $sVerify Then Return SetError(1) If $sVerify == $sPass Then ;MSGBOX(0, "TEST 2", "Verified") Return $sPass Else ;MsgBox(0, "TEST 3", $sPass & @CRLF & $sVerify) _Password() EndIF EndIf Else _Error() _PassWord() EndIfElse Return SetError(1)EndIfEndFuncFunc _Error() MsgBox(0,"Invalid Password", "The Password must be at least 8 Characters and contain" & _ " a combination of Upper and Lower case letters with at least 1 number.")EndFuncFunc _Check($iChk) Switch $iChk Case 1 $sChk = "[a-z]" Case 2 $sChk = "[A-Z]" Case 3 $sChk = "[0-9]" Case Else Return 0 EndSwitch If StringRegExp($SPass, $sChk) Then Return 1 Return 0EndFunc@GEOSoftI'm not good with StringRegExp, but your check function is something I can use in other stuff too.The only slight drawback is the fact it uses more than 1 function, But I Dont suppose this matters much, But apart from that I am sure it won't take long to build in the complexity as a variable, then it will be good!!I am busy finishing off another program at the moment, I have 2 practically ready to upload..... But it is on my list of stuff to do, I will probably end up building alot of your script within my scripts many if tests... If StringRegExp($SPass, $sChk) Then Return 1 Return 0?? won't the return 0 overide the return 1 as they are both being sent? or am I being stupid? Edit: Being stupid!$sPass = ""$sPass = InputBox("Password", "Please enter your password", "", "*")is this to make a return value of "" if they cancel? Edited April 14, 2009 by mdiesel AutoIt Project Listing
GEOSoft Posted April 14, 2009 Posted April 14, 2009 (edited) If StringRegExp($SPass, $sChk) Then Return 1 Return 0 ?? won't the return 0 overide the return 1 as they are both being sent? or am I being stupid?No. If the RegEx is valid then it returns 1 so it never gets to he second return. Once you return something the function ends. $sPass = "" $sPass = InputBox("Password", "Please enter your password", "", "*") is this to make a return value of "" if they cancel?Not really. I put that in to make sure $sPass was reset if the function was called again because of an invalid entry somewhere. EDIT: I should also point out wht the RegEps are checking; [a-z] = Lowercase alpha anywhere in the string [A-Z] = Uppercase alpha anywhere in the string. [0-9] = digit anyplace in the string The function returns 1 each time the match is valid. The value is added to $iValid which must total 3 to be a valid check. No need for string splits this way. Edited April 14, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Mat Posted April 14, 2009 Author Posted April 14, 2009 (edited) What am I doing wrong here? It runs, but it thinks there are numbers and capitals in where there aren't, and capitals too, in fact, everything ive edited to ude stringregexp!! CODEMsgBox (48, "Result", _PasswordCreate (31)) Func _PasswordCreate ($Complexity) Local $Pass, $ConfirmPass, $m If BitAND($complexity, 2) Then $m = "M" Else $m = "" EndIf Do $Pass = InputBox ("Password", "Please enter your password", "", "*" & $m) If @Error Then Return SetError (1); Pass box cancelled If BitAND($complexity, 4) Then If StringLen ($Pass) < 8 Then MsgBox (48, "Error", "Pass is less than 8 character!") $ConfirmPass = "" ContinueLoop EndIf EndIf If BitAND($complexity, 8) Then If StringRegExp($Pass, "[0-9]") Then MsgBox (48, "Error", "Pass contains no numbers!") $ConfirmPass = "" ContinueLoop EndIf EndIf If BitAND($complexity, 16) Then If StringRegExp($Pass, "[A-Z]") Then MsgBox (48, "Error", "Pass contains no capitals!") $ConfirmPass = "" ContinueLoop EndIf EndIf If BitAND($complexity, 1) Then $ConfirmPass = InputBox ("Password", "Please Confirm your password", "", "*") If $Pass <> $ConfirmPass Then MsgBox (48, "Error", "Passwords do not match!!") Else $Pass = $ConfirmPass EndIf Until $Pass = $ConfirmPass Return $Pass EndFunc; ==> _PasswordCreate Edited April 14, 2009 by mdiesel AutoIt Project Listing
GEOSoft Posted April 14, 2009 Posted April 14, 2009 (edited) If BitAND($complexity, 8) Then If StringRegExp($Pass, "[0-9]") Then MsgBox (48, "Error", "Pass contains no numbers!") $ConfirmPass = "" ContinueLoop EndIf EndIf If BitAND($complexity, 16) Then If StringRegExp($Pass, "[A-Z]") Then MsgBox (48, "Error", "Pass contains no capitals!") $ConfirmPass = "" ContinueLoop EndIf EndIf Those regexps will return 1 if they are valid, so the way to do them would be with If NOT StringRegExp(.....) Then Also I don't see where you have checked for lower case either. This is a situation where a separate function is easier Edited April 14, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Mat Posted April 14, 2009 Author Posted April 14, 2009 (edited) OK, With only one function: CODEFunc _PasswordCreate ($Complexity) Local $Pass, $ConfirmPass, $m If BitAND($complexity, 2) Then $m = "M" Else $m = "" EndIf Do $Pass = InputBox ("Password", "Please enter your password", "", "*" & $m) If @Error Then Return SetError (1); Pass box cancelled If BitAND($complexity, 4) Then If StringLen ($Pass) < 8 Then MsgBox (48, "Error", "Pass is less than 8 character!") $ConfirmPass = "" ContinueLoop EndIf EndIf If BitAND($complexity, 8) Then If Not StringRegExp($Pass, "[0-9]") Then MsgBox (48, "Error", "Pass contains no numbers!") $ConfirmPass = "" ContinueLoop EndIf EndIf If BitAND($complexity, 16) Then If Not StringRegExp($Pass, "[A-Z]") Then MsgBox (48, "Error", "Pass contains no capitals!") $ConfirmPass = "" ContinueLoop EndIf EndIf If BitAND($complexity, 16) Then If Not StringRegExp($Pass, "[a-z]") Then MsgBox (48, "Error", "Pass contains no lowercase letters!") $ConfirmPass = "" ContinueLoop EndIf EndIf If BitAND($complexity, 1) Then $ConfirmPass = InputBox ("Password", "Please Confirm your password", "", "*") If $Pass <> $ConfirmPass Then MsgBox (48, "Error", "Passwords do not match!!") Else ExitLoop EndIf Until $Pass = $ConfirmPass Return $Pass EndFunc; ==> _PasswordCreate With the functions, all I'm doing is replacing StringRegExp($Pass, "[a-z]") with _Check(1)...thats probably becouse I'm doing something wrong though....The problem is getting it to mix in with complexity being a variable. Edited April 14, 2009 by mdiesel AutoIt Project Listing
GEOSoft Posted April 14, 2009 Posted April 14, 2009 I'm laying down at the moment so I'll test it later, but right off the top I spotted ths which will not do what you want. If $Pass <> $ConfirmPass Example: If $Pass = aA123456 and $Confirm = Aa123456 Then $Pass is equal to $Confirm but it would not match If NOT $Pass == $Confirm which requires that the match for case. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Mat Posted April 14, 2009 Author Posted April 14, 2009 (edited) Thanks again, code edited.done a few other edits too.Edit;heres a similar thing that resnullius did: it sows the complexity as a colour value, might toy around with that and see if i can get a sort of progress bar to work on it. found hereCODE#include <GUIConstants.au3>Global $bars = 45;based on score required for "strong" ratingGlobal $grad_bars[$bars + 1] = [$bars]Global $pbOldValue = 0$pbMeterLeft = 16$pbMeterTop = 120$pbMeterWidth = 388$pbMeterHeight = 28$BrGreen = 0x00FF00$BrRed = 0xE71800$start_Color = $BrGreen$target_color = $BrRed$barWidth = $pbMeterWidth / $bars$barLeft = $pbMeterLeft$value = 0$hGUI = GUICreate("Password Tester", 438, 378, 193, 126)GUICtrlCreateLabel("Password:", 14, 17, 53, 17)$gcPWField = GUICtrlCreateEdit("", 14, 39, 390, 76, $WS_VSCROLL, $WS_EX_CLIENTEDGE)$gcStrength = GUICtrlCreateLabel("Strength:", 16, 160, 100, 17)$gcScore = GUICtrlCreateLabel("Score:", 153, 160, 100, 17)$gcRTField = GUICtrlCreateEdit("", 14, 186, 393, 178, $ES_READONLY + $WS_VSCROLL, $WS_EX_CLIENTEDGE)$pBarMeter = GUICtrlCreateGraphic($pbMeterLeft - 1, $pbMeterTop - 1, $pbMeterWidth + 2, $pbMeterHeight + 2, $SS_SUNKEN)For $bar = 1 To $bars $grad_bars[$bar] = GUICtrlCreateLabel("", $barLeft, $pbMeterTop, $barWidth+1, $pbMeterHeight) $barLeft += ($barWidth)NextFor $i = 1 To $bars $target_color_str = _MakeGradLineColors($start_Color, $target_color, ($bars - $i));/2);$value - $i) GUICtrlSetBkColor($grad_bars[$i], $target_color_str) GUICtrlSetState($grad_bars[$i], $GUI_HIDE)NextGUISetState(@SW_SHOW)Local $a, $s = ''While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case Else If GUICtrlRead($gcPWField) <> $s Then $s = GUICtrlRead($gcPWField) $a = testPassword($s) GUICtrlSetData($gcStrength, "Strength: " & $a[1]) GUICtrlSetData($gcScore, "Score: " & $a[0]) GUICtrlSetData($gcRTField, $a[2]) _pBarRefresh($a[0]) EndIf EndSwitchWEndFunc testPassword($passwd) Local $intScore = 0 Local $strVerdict = "weak" Local $strLog = "" Local $intPWlen = StringLen($passwd) ; PASSWORD LENGTH If ($intPWlen < 5) Then ; length 4 or less $intScore += 3 $strLog &= "3 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 4 And $intPWlen < 8) Then; length between 5 and 7 $intScore += 6 $strLog &= "6 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 7 And $intPWlen < 16) Then; length between 8 and 15 $intScore += 12 $strLog &= "12 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 15) Then ; length 16 or more $intScore += 18 $strLog &= "18 point for length (" & $intPWlen & ")\r\n" EndIf ; LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex) If StringRegExp($passwd, '[a-z]') Then ;// [verified] at least one lower case letter $intScore += 1 $strLog &= "1 point for at least one lower case char\r\n" EndIf If StringRegExp($passwd, '[A-Z]') Then ; // [verified] at least one upper case letter $intScore += 5 $strLog &= "5 points for at least one upper case char\r\n" EndIf ; NUMBERS If StringRegExp($passwd, '\d+') Then ;// [verified] at least one number $intScore += 5 $strLog &= "5 points for at least one number\r\n" EndIf If StringRegExp($passwd, '(.*[0-9].*[0-9].*[0-9])') Then ;// [verified] at least three numbers $intScore += 5 $strLog &= "5 points for at least three numbers\r\n" EndIf ; SPECIAL CHAR If StringRegExp($passwd, '.[!,@,#,$,%,^,&,*,?,_,~]') Then ;// [verified] at least one special character $intScore += 5 $strLog &= "5 points for at least one special char\r\n" EndIf If StringRegExp($passwd, '(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])') Then $intScore += 5 $strLog &= "5 points for at least two special chars\r\n" ; // [verified] at least two special characters EndIf ; COMBOS If StringRegExp($passwd, '([a-z].*[A-Z])|([A-Z].*[a-z])') Then ;// [verified] both upper and lower case $intScore += 2 $strLog &= "2 combo points for upper and lower letters\r\n" EndIf If StringRegExp($passwd, '([a-zA-Z])/') And StringRegExp($passwd, '/([0-9])') Then;// [verified] both letters and numbers $intScore += 2 $strLog &= "2 combo points for letters and numbers\r\n" EndIf If StringRegExp($passwd, '([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])') Then $intScore += 2 ;// [verified] letters, numbers, and special characters $strLog &= "2 combo points for letters, numbers and special chars\r\n" EndIf ;Verdict If ($intScore < 16) Then $strVerdict = "very weak" ElseIf ($intScore > 15 And $intScore < 25) Then $strVerdict = "weak" ElseIf ($intScore > 24 And $intScore < 35) Then $strVerdict = "mediocre" ElseIf ($intScore > 34 And $intScore < 45) Then $strVerdict = "strong" Else $strVerdict = "stronger" EndIf Local $aArray[3] = [$intScore, $strVerdict, StringFormat($strLog) ] Return $aArrayEndFunc ;==>testPasswordFunc _pBarRefresh($pbValue) If $pbValue > $bars Then $pbValue = $bars If $pbValue < $pbOldValue Then For $i = $bars To ($pbValue + 1) Step - 1 GUICtrlSetState($grad_bars[$i], $GUI_HIDE) Sleep(1) Next EndIf If $pbValue > $pbOldValue Then For $i = 1 To $pbValue GUICtrlSetState($grad_bars[$i], $GUI_SHOW) Sleep(1) Next EndIf $pbOldValue = $pbValue ; EndIf ReturnEndFunc ;==>_pBarRefreshFunc _MakeGradLineColors($start_Color, $target_color, $i) Local $g_red = GetColorRed($start_Color) Local $g_green = GetColorGreen($start_Color) Local $g_blue = GetColorBlue($start_Color) Local $g_r_step = (GetColorRed($target_color) - $g_red) / $bars;$value;$cpc_grad_step Local $g_g_step = (GetColorGreen($target_color) - $g_green) / $bars;$value;$cpc_grad_step Local $g_b_step = (GetColorBlue($target_color) - $g_blue) / $bars;$value;$cpc_grad_step Return "0x" & StringFormat("%02X%02X%02X", $g_red + $g_r_step * $i, $g_green + $g_g_step * $i, $g_blue + $g_b_step * $i)EndFunc ;==>_MakeGradLineColors; The standard AutoIt UDF color functions; re-named and here for convenience;Func GetColorRed($nColor) Return BitAND(BitShift($nColor, 16), 0xff)EndFunc ;==>GetColorRedFunc GetColorGreen($nColor) Return BitAND(BitShift($nColor, 8), 0xff)EndFunc ;==>GetColorGreenFunc GetColorBlue($nColor) Return BitAND($nColor, 0xff)EndFunc ;==>GetColorBlue Edited April 14, 2009 by mdiesel AutoIt Project Listing
GEOSoft Posted April 14, 2009 Posted April 14, 2009 Better. On the two RegExps for Special characters. 1- They don't need to be comma separated 2 - You could just use "[[:punct:]]" instead of "[!,@,#,$,%,^,&,*,?,_,~]" If you want those to be a bit more versatile then "[[:punct:]\x80-\xff]", Which allows usage of the Extended Character set for the spacial characters George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
ResNullius Posted April 14, 2009 Posted April 14, 2009 heres a similar thing that resnullius did: it sows the complexity as a colour value, might toy around with that and see if i can get a sort of progress bar to work on it. found here@mdiesel,You should keep the attributions in the code so people can look up the original sources, and credit is given (to all) where credit is due.You also won't end up thinking you made it all up yourself when you look at it in years to come. ;http://www.autoitscript.com/forum/index.php?s=&showtopic=54181&view=findpost&p=410541;Kastout (was mrRevoked);;http://www.geekwisdom.com/dyn/passwdmeter;;this version by ResNullius;;colour gradient routines lifted from corz's "color pickin chooser" @;http://www.autoitscript.com/forum/index.php?s=&showtopic=53840&view=findpost&p=407811;
Mat Posted April 14, 2009 Author Posted April 14, 2009 (edited) sorry res and whoever else i missed, I was in a rush last night, and cut up and looked at the code before saving it, i then posted the saved code (practically no difference apart from the comments).In the original functions I psted, I stayed well clear of using udfs, so used input boxes instead...This was to save a lot on complexity, i might go back on that idea now and see if i can build in the whole strength thing into a smaller box, basically an input box with a label that says the word - but leaves out score and points, or I could completely redo it, and set $graphics in the same way as complexity...with full thanks kept in the comments...anyway: playing with the code got me this: I tried to make it smaller, which succeeded (multiline passwords arent needed), but the button does not work - i am presuming im doing something wrong with GUISetCoords, as I looked around and included what options I could find.***New Code has been put in a couple of posts down***CODE;http://www.autoitscript.com/forum/index.php?s=&showtopic=54181&view=findpost&p=410541;mrRevoked;;http://www.geekwisdom.com/dyn/passwdmeter;;this version by ResNullius;;colour gradient routines lifted from corz's "color pickin chooser" @;http://www.autoitscript.com/forum/index.php?s=&showtopic=53840&view=findpost&p=407811;#include <GUIConstantsex.au3>#include <EditConstants.au3>#include <WindowsConstants.au3>#include <StaticConstants.au3>Opt("GUICoordMode", 1) Global $bars = 45;based on score required for "strong" ratingGlobal $grad_bars[$bars + 1] = [$bars]Global $pbOldValue = 0$pbMeterLeft = 10$pbMeterTop = 40$pbMeterWidth = 420$pbMeterHeight = 30$BrGreen = 0x00FF00$BrRed = 0xE71800$start_Color = $BrGreen$target_color = $BrRed$barWidth = $pbMeterWidth / $bars$barLeft = $pbMeterLeft$value = 0$hGUI = GUICreate("Password Tester", 440, 110, 200, 130)GUICtrlCreateLabel("Password:", 10, 12, 60, 20)$gcPWField = GUICtrlCreateInput("", 80, 10, 350, 20, $WS_VSCROLL, $WS_EX_CLIENTEDGE)$pBarMeter = GUICtrlCreateGraphic($pbMeterLeft, $pbMeterTop, $pbMeterWidth, $pbMeterHeight, $SS_SUNKEN)$gcStrength = GUICtrlCreateLabel("Strength:", 10, 80, 100, 20)$gcScore = GUICtrlCreateLabel("Score:", 150, 80, 100, 20)$PntsShow = GUICtrlCreateButton ("Show Points >>", 330, 80, 100, 20); Hidden becouse of GUI size$gcRTField = GUICtrlCreateEdit("", 10, 110, 400, 180, $ES_READONLY + $WS_VSCROLL, $WS_EX_CLIENTEDGE)For $bar = 1 To $bars$grad_bars[$bar] = GUICtrlCreateLabel("", $barLeft, $pbMeterTop, $barWidth+1, $pbMeterHeight)$barLeft += ($barWidth)NextFor $i = 1 To $bars$target_color_str = _MakeGradLineColors($start_Color, $target_color, ($bars - $i));/2);$value - $i)GUICtrlSetBkColor($grad_bars[$i], $target_color_str)GUICtrlSetState($grad_bars[$i], $GUI_HIDE)NextGUISetState(@SW_SHOW)Local $a, $s = ''While 1$msg = GUIGetMsg()Switch $msgCase $PntsShowIf GUICtrlRead ($PntsShow) <> "<< HidePoints" Then GUICtrlSetData ($PntsShow, "<< HidePoints") GUISetCoord (-1, -1, 440, 520, $hGUI)Else GUICtrlSetData ($PntsShow, "Show Points >>") GUISetCoord (-1, -1, 440, 110, $hGUI)EndIfCase $GUI_EVENT_CLOSEExitCase ElseIf GUICtrlRead($gcPWField) <> $s Then$s = GUICtrlRead($gcPWField)$a = testPassword($s)GUICtrlSetData($gcStrength, "Strength: " & $a[1])GUICtrlSetData($gcScore, "Score: " & $a[0])GUICtrlSetData($gcRTField, $a[2])_pBarRefresh($a[0])EndIfEndSwitchWEndFunc testPassword($passwd)Local $intScore = 0Local $strVerdict = "weak"Local $strLog = ""Local $intPWlen = StringLen($passwd); PASSWORD LENGTHIf ($intPWlen < 5) Then ; length 4 or less$intScore += 3$strLog &= "3 points for length (" & $intPWlen & ")\r\n"ElseIf ($intPWlen > 4 And $intPWlen < 8) Then; length between 5 and 7$intScore += 6$strLog &= "6 points for length (" & $intPWlen & ")\r\n"ElseIf ($intPWlen > 7 And $intPWlen < 16) Then; length between 8 and 15$intScore += 12$strLog &= "12 points for length (" & $intPWlen & ")\r\n"ElseIf ($intPWlen > 15) Then ; length 16 or more$intScore += 18$strLog &= "18 point for length (" & $intPWlen & ")\r\n"EndIf; LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)If StringRegExp($passwd, '[a-z]') Then ;// [verified] at least one lower case letter$intScore += 1$strLog &= "1 point for at least one lower case char\r\n"EndIfIf StringRegExp($passwd, '[A-Z]') Then ; // [verified] at least one upper case letter$intScore += 5$strLog &= "5 points for at least one upper case char\r\n"EndIf; NUMBERSIf StringRegExp($passwd, '\d+') Then ;// [verified] at least one number$intScore += 5$strLog &= "5 points for at least one number\r\n"EndIfIf StringRegExp($passwd, '(.*[0-9].*[0-9].*[0-9])') Then ;// [verified] at least three numbers$intScore += 5$strLog &= "5 points for at least three numbers\r\n"EndIf; SPECIAL CHARIf StringRegExp($passwd, '.[!,@,#,$,%,^,&,*,?,_,~]') Then ;// [verified] at least one special character$intScore += 5$strLog &= "5 points for at least one special char\r\n"EndIfIf StringRegExp($passwd, '(.*[[:punct:]\x80-\xff].*[[:punct:]\x80-\xff])') Then$intScore += 5$strLog &= "5 points for at least two special chars\r\n" ; // [verified] at least two special charactersEndIf; COMBOSIf StringRegExp($passwd, '([a-z].*[A-Z])|([A-Z].*[a-z])') Then ;// [verified] both upper and lower case$intScore += 2$strLog &= "2 combo points for upper and lower letters\r\n"EndIfIf StringRegExp($passwd, '([a-zA-Z])/') And StringRegExp($passwd, '/([0-9])') Then;// [verified] both letters and numbers$intScore += 2$strLog &= "2 combo points for letters and numbers\r\n"EndIfIf StringRegExp($passwd, '([a-zA-Z0-9].*[[:punct:]\x80-\xff])|([[:punct:]\x80-\xff].*[a-zA-Z0-9])') Then$intScore += 2 ;// [verified] letters, numbers, and special characters$strLog &= "2 combo points for letters, numbers and special chars\r\n"EndIf;VerdictIf ($intScore < 16) Then$strVerdict = "very weak"ElseIf ($intScore > 15 And $intScore < 25) Then$strVerdict = "weak"ElseIf ($intScore > 24 And $intScore < 35) Then$strVerdict = "mediocre"ElseIf ($intScore > 34 And $intScore < 45) Then$strVerdict = "strong"Else$strVerdict = "stronger"EndIfLocal $aArray[3] = [$intScore, $strVerdict, StringFormat($strLog) ]Return $aArrayEndFunc ;==>testPasswordFunc _pBarRefresh($pbValue)If $pbValue > $bars Then $pbValue = $barsIf $pbValue < $pbOldValue ThenFor $i = $bars To ($pbValue + 1) Step - 1GUICtrlSetState($grad_bars[$i], $GUI_HIDE)Sleep(1)NextEndIfIf $pbValue > $pbOldValue ThenFor $i = 1 To $pbValueGUICtrlSetState($grad_bars[$i], $GUI_SHOW)Sleep(1)NextEndIf$pbOldValue = $pbValue; EndIfReturnEndFunc ;==>_pBarRefreshFunc _MakeGradLineColors($start_Color, $target_color, $i)Local $g_red = GetColorRed($start_Color)Local $g_green = GetColorGreen($start_Color)Local $g_blue = GetColorBlue($start_Color)Local $g_r_step = (GetColorRed($target_color) - $g_red) / $bars;$value;$cpc_grad_stepLocal $g_g_step = (GetColorGreen($target_color) - $g_green) / $bars;$value;$cpc_grad_stepLocal $g_b_step = (GetColorBlue($target_color) - $g_blue) / $bars;$value;$cpc_grad_stepReturn "0x" & StringFormat("%02X%02X%02X", $g_red + $g_r_step * $i, $g_green + $g_g_step * $i, $g_blue + $g_b_step * $i)EndFunc ;==>_MakeGradLineColors; The standard AutoIt UDF color functions; re-named and here for convenience;Func GetColorRed($nColor)Return BitAND(BitShift($nColor, 16), 0xff)EndFunc ;==>GetColorRedFunc GetColorGreen($nColor)Return BitAND(BitShift($nColor, 8), 0xff)EndFunc ;==>GetColorGreenFunc GetColorBlue($nColor)Return BitAND($nColor, 0xff)EndFunc ;==>GetColorBluePS. I'm out tonight, so please don't get angry at me when I don't answer your questions straight away... Edited April 15, 2009 by mdiesel AutoIt Project Listing
GEOSoft Posted April 14, 2009 Posted April 14, 2009 (edited) You're getting it fine-tuned now. You missed 1 special character replacement. If StringRegExp($passwd, '.[!,@,#,$,%,^,&,*,?,_,~]') Then If StringRegExp($passwd, '[[:punct:]\x80-\xff]') Then EDIT: Note that I also removed the dot from the beginning of your RegExp. If the Special Character was not precedded by a character then yours will fail. In other words it will fail if the special Character of the string is first. Example ©AaBbCc12 You can put it back in but it should be .* Edited April 14, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Mat Posted April 15, 2009 Author Posted April 15, 2009 (edited) Kk, thanks geosoft, but still no idea why GUISetCoord is not working? I tried changing the GUICoordMode to make it relative (0), still nothing. Heres the start of the while loop: While 1 $msg = GUIGetMsg() Switch $msg Case $PntsShow If GUICtrlRead ($PntsShow) <> "<< HidePoints" Then GUICtrlSetData ($PntsShow, "<< HidePoints") GUISetCoord (0, 0, 0, 410, $hGUI) Else GUICtrlSetData ($PntsShow, "Show Points >>") GUISetCoord (0, 0, 0, -410, $hGUI) EndIf Full Code: CODE ;http://www.autoitscript.com/forum/index.php?s=&showtopic=54181&view=findpost&p=410541 ;mrRevoked ; ;http://www.geekwisdom.com/dyn/passwdmeter ; ;this version by ResNullius, edited by MDiesel ; ;colour gradient routines lifted from corz's "color pickin chooser" @ ;http://www.autoitscript.com/forum/index.php?s=&showtopic=53840&view=findpost&p=407811 #include <GUIConstantsex.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> Opt("GUICoordMode", 0) Global $bars = 45;based on score required for "strong" rating Global $grad_bars[$bars + 1] = [$bars] Global $pbOldValue = 0 $pbMeterLeft = 10 $pbMeterTop = 40 $pbMeterWidth = 420 $pbMeterHeight = 30 $BrGreen = 0x00FF00 $BrRed = 0xE71800 $start_Color = $BrGreen $target_color = $BrRed $barWidth = $pbMeterWidth / $bars $barLeft = $pbMeterLeft $value = 0 $hGUI = GUICreate("Password Tester", 440, 110, 200, 130) GUICtrlCreateLabel("Password:", 10, 12, 60, 20) $gcPWField = GUICtrlCreateInput("", 70, 0, 350, 20, $WS_VSCROLL, $WS_EX_CLIENTEDGE) $pBarMeter = GUICtrlCreateGraphic($pbMeterLeft, $pbMeterTop, $pbMeterWidth, $pbMeterHeight, $SS_SUNKEN) $gcStrength = GUICtrlCreateLabel("Strength:", -70, 70, 100, 20) $gcScore = GUICtrlCreateLabel("Score:", 150, 0, 100, 20) $PntsShow = GUICtrlCreateButton ("Show Points >>", 160, -5, 100, 20) ; Hidden becouse of GUI size $gcRTField = GUICtrlCreateEdit("", 10, 110, 400, 180, $ES_READONLY + $WS_VSCROLL, $WS_EX_CLIENTEDGE) For $bar = 1 To $bars $grad_bars[$bar] = GUICtrlCreateLabel("", $barLeft, $pbMeterTop, $barWidth+1, $pbMeterHeight) $barLeft += ($barWidth) Next For $i = 1 To $bars $target_color_str = _MakeGradLineColors($start_Color, $target_color, ($bars - $i));/2);$value - $i) GUICtrlSetBkColor($grad_bars[$i], $target_color_str) GUICtrlSetState($grad_bars[$i], $GUI_HIDE) Next GUISetState(@SW_SHOW) Local $a, $s = '' While 1 $msg = GUIGetMsg() Switch $msg Case $PntsShow If GUICtrlRead ($PntsShow) <> "<< HidePoints" Then GUICtrlSetData ($PntsShow, "<< HidePoints") GUISetCoord (0, 0, 0, 410, $hGUI) Else GUICtrlSetData ($PntsShow, "Show Points >>") GUISetCoord (0, 0, 0, -410, $hGUI) EndIf Case $GUI_EVENT_CLOSE Exit Case Else If GUICtrlRead($gcPWField) <> $s Then $s = GUICtrlRead($gcPWField) $a = testPassword($s) GUICtrlSetData($gcStrength, "Strength: " & $a[1]) GUICtrlSetData($gcScore, "Score: " & $a[0]) GUICtrlSetData($gcRTField, $a[2]) _pBarRefresh($a[0]) EndIf EndSwitch WEnd Func testPassword($passwd) Local $intScore = 0 Local $strVerdict = "weak" Local $strLog = "" Local $intPWlen = StringLen($passwd) ; PASSWORD LENGTH If ($intPWlen < 5) Then ; length 4 or less $intScore += 3 $strLog &= "3 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 4 And $intPWlen < 8) Then; length between 5 and 7 $intScore += 6 $strLog &= "6 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 7 And $intPWlen < 16) Then; length between 8 and 15 $intScore += 12 $strLog &= "12 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 15) Then ; length 16 or more $intScore += 18 $strLog &= "18 point for length (" & $intPWlen & ")\r\n" EndIf ; LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex) If StringRegExp($passwd, '[a-z]') Then ;// [verified] at least one lower case letter $intScore += 1 $strLog &= "1 point for at least one lower case char\r\n" EndIf If StringRegExp($passwd, '[A-Z]') Then ; // [verified] at least one upper case letter $intScore += 5 $strLog &= "5 points for at least one upper case char\r\n" EndIf ; NUMBERS If StringRegExp($passwd, '\d+') Then ;// [verified] at least one number $intScore += 5 $strLog &= "5 points for at least one number\r\n" EndIf If StringRegExp($passwd, '(.*[0-9].*[0-9].*[0-9])') Then ;// [verified] at least three numbers $intScore += 5 $strLog &= "5 points for at least three numbers\r\n" EndIf ; SPECIAL CHAR If StringRegExp($passwd, '[[:punct:]\x80-\xff]') Then ;// [verified] at least one special character $intScore += 5 $strLog &= "5 points for at least one special char\r\n" EndIf If StringRegExp($passwd, '(.*[[:punct:]\x80-\xff].*[[:punct:]\x80-\xff])') Then $intScore += 5 $strLog &= "5 points for at least two special chars\r\n" ; // [verified] at least two special characters EndIf ; COMBOS If StringRegExp($passwd, '([a-z].*[A-Z])|([A-Z].*[a-z])') Then ;// [verified] both upper and lower case $intScore += 2 $strLog &= "2 combo points for upper and lower letters\r\n" EndIf If StringRegExp($passwd, '([a-zA-Z])/') And StringRegExp($passwd, '/([0-9])') Then;// [verified] both letters and numbers $intScore += 2 $strLog &= "2 combo points for letters and numbers\r\n" EndIf If StringRegExp($passwd, '([a-zA-Z0-9].*[[:punct:]\x80-\xff])|([[:punct:]\x80-\xff].*[a-zA-Z0-9])') Then $intScore += 2 ;// [verified] letters, numbers, and special characters $strLog &= "2 combo points for letters, numbers and special chars\r\n" EndIf ;Verdict If ($intScore < 16) Then $strVerdict = "very weak" ElseIf ($intScore > 15 And $intScore < 25) Then $strVerdict = "weak" ElseIf ($intScore > 24 And $intScore < 35) Then $strVerdict = "mediocre" ElseIf ($intScore > 34 And $intScore < 45) Then $strVerdict = "strong" Else $strVerdict = "stronger" EndIf Local $aArray[3] = [$intScore, $strVerdict, StringFormat($strLog) ] Return $aArray EndFunc ;==>testPassword Func _pBarRefresh($pbValue) If $pbValue > $bars Then $pbValue = $bars If $pbValue < $pbOldValue Then For $i = $bars To ($pbValue + 1) Step - 1 GUICtrlSetState($grad_bars[$i], $GUI_HIDE) Sleep(1) Next EndIf If $pbValue > $pbOldValue Then For $i = 1 To $pbValue GUICtrlSetState($grad_bars[$i], $GUI_SHOW) Sleep(1) Next EndIf $pbOldValue = $pbValue ; EndIf Return EndFunc ;==>_pBarRefresh Func _MakeGradLineColors($start_Color, $target_color, $i) Local $g_red = GetColorRed($start_Color) Local $g_green = GetColorGreen($start_Color) Local $g_blue = GetColorBlue($start_Color) Local $g_r_step = (GetColorRed($target_color) - $g_red) / $bars;$value;$cpc_grad_step Local $g_g_step = (GetColorGreen($target_color) - $g_green) / $bars;$value;$cpc_grad_step Local $g_b_step = (GetColorBlue($target_color) - $g_blue) / $bars;$value;$cpc_grad_step Return "0x" & StringFormat("%02X%02X%02X", $g_red + $g_r_step * $i, $g_green + $g_g_step * $i, $g_blue + $g_b_step * $i) EndFunc ;==>_MakeGradLineColors ; The standard AutoIt UDF color functions ; re-named and here for convenience ; Func GetColorRed($nColor) Return BitAND(BitShift($nColor, 16), 0xff) EndFunc ;==>GetColorRed Func GetColorGreen($nColor) Return BitAND(BitShift($nColor, 8), 0xff) EndFunc ;==>GetColorGreen Func GetColorBlue($nColor) Return BitAND($nColor, 0xff) EndFunc ;==>GetColorBlue Edited April 15, 2009 by mdiesel AutoIt Project Listing
WideBoyDixon Posted April 15, 2009 Posted April 15, 2009 (edited) You can check password adherence to complexity rules using a single regular expression. For example, my rules are:- Must be at least 10 characters long- Must have at least one uppercase character- Must have at least one lowercase character- Must have at least one number- Must have at least one "special" character from the set [@#$%^&+=]My regular expression is then "^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$"Taking this one step further I wrote a UDF to check that a password conforms to rules. The list of special characters might need tweaking for your own personal tastes.Func _CheckPasswordComplexity($sPassword, $iMinLength, $iDigits = 0, $iLowerCase = 0, $iUpperCase = 0, $iSpecialChars = 0) Local $sRegExp = "^.*(?=.{" & $iMinLength & ",})" If $iDigits > 0 Then $sRegExp &= "(?=.*\d{" & $iDigits & ",})" If $iLowerCase > 0 Then $sRegExp &= "(?=.*[a-z]{" & $iLowerCase & ",})" If $iUpperCase > 0 Then $sRegExp &= "(?=.*[A-Z]{" & $iLowerCase & ",})" If $iSpecialChars > 0 Then $sRegExp &= "(?=.*[@#$%^&+=]{" & $iSpecialChars & ",})" $sRegExp &= ".*$" Local $iResult = StringRegExp($sPassword, $sRegExp) If @error = 0 Then Return SetError(0, 0, ($iResult <> 0)) Else Return SetError(1, 0, 0) EndIf EndFuncWBD Edited April 15, 2009 by WideBoyDixon [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center]
Mat Posted April 15, 2009 Author Posted April 15, 2009 (edited) Very nice, except you can't return the particular problem... building it in to create a pass: CODEFunc _PasswordCreate ($iMinLength, $Confirm, $iDigits = 0, $iLowerCase = 0, $iUpperCase = 0, $iSpecialChars = 0) Local $Pass, $ConfirmPass, $Error If $iMinLength > 0 Then $m = "M" Else $m = "" EndIf Do $Pass = InputBox ("Password", "Please enter your password", "", "*" & $m) If @Error Then Return SetError (1) ; Pass box cancelled If _CheckPasswordComplexity($Pass, $iMinLength, $iDigits, $iLowerCase, $iUpperCase, $iSpecialChars) = 0 Then $Error = "Password does not conform to the rules, it must have: " If $iMinLength > 0 Then $Error &= "a minimum length of " & $iMinLength & " Characters, " If $iDigits > 0 Then $Error &= "at least " & $iDigits & " Numbers, " If $iLowerCase > 0 Then $Error &= $iLowerCase & " lowercase characters or more, " If $iUpperCase > 0 Then $Error &= "no less than " & $iUpperCase & " Uppercase characters, " If $iSpecialChars > 0 Then $Error &= "at least " & $iSpecialChars & " Special characters such as punctuation, " $Error &= "Please change your password appropriately." MsgBox (48, "Error", $Error) ContinueLoop Else If $Confirm <> 0 Then $ConfirmPass = InputBox ("Password", "Please Confirm your password", "", "*") If Not $ConfirmPass == $Pass Then MsgBox (48, "Error", "Passwords do not match") Else ExitLoop EndIf EndIf Until $Pass == $ConfirmPass Return $Pass EndFunc ; ==> _PasswordCreate Func _CheckPasswordComplexity($sPassword, $iMinLength, $iDigits = 0, $iLowerCase = 0, $iUpperCase = 0, $iSpecialChars = 0) Local $sRegExp = "^.*(?=.{" & $iMinLength & ",})" If $iDigits > 0 Then $sRegExp &= "(?=.*\d{" & $iDigits & ",})" If $iLowerCase > 0 Then $sRegExp &= "(?=.*[a-z]{" & $iLowerCase & ",})" If $iUpperCase > 0 Then $sRegExp &= "(?=.*[A-Z]{" & $iLowerCase & ",})" If $iSpecialChars > 0 Then $sRegExp &= "(?=.*[@#$%^&+=]{" & $iSpecialChars & ",})" $sRegExp &= ".*$" Local $iResult = StringRegExp($sPassword, $sRegExp) If @error = 0 Then Return SetError(0, 0, ($iResult <> 0)) Else Return SetError(1, 0, 0) EndIf EndFunc still no answer to GUISetCoord? edit: I'm probably going to post it in h+s if i don't get any answers here. Edited April 15, 2009 by mdiesel AutoIt Project Listing
GEOSoft Posted April 15, 2009 Posted April 15, 2009 I was busy so I just got to look at it a couple of minutes ago. I don't have testing time right now but at first glance you have all the control coordinates set wrong. Opt("GUICoordMode", 2) Then When you create the controls, create the first at the coordinates where you want to start. I usually start at 10, 10 but that's up to you after that use 0, -1 to keep them on the same row or -1, 0 to move down a row. Note the 0s can be changed to space the horiz or vert positioning. If you have two or three controls on a row then you have to add the width of the controls and any spacing thats used and replace the -1, 0 to - (your total), 0 OR use GUISetCoord() and the next control will be at -1, -1 Here is an example of one I'm just starting in a multi-form script that will give you the general idea. expandcollapse popup; Func _Opts() Local $Frm_Opts = GUICreate("Options", 250, 195) GUISetFont(8.5) Local $Lbl_copies_1 = GUICtrlCreateLabel("Keep last", 10, 10, 50, 20) Local $in_Copies = GUICtrlCreateInput($iMaxS, 0, -1, 20) Local $Lbl_copies_2 = GUICtrlCreateLabel("searches and URLs", 10, -1, 100) Local $Lbl_data = GUICtrlCreateLabel("Temp Readings", -180, 10, 90) GUIStartGroup() Local $Rad_Default = GUICtrlCreateRadio("Default", -1, 0, 60) Local $Rad_US = GUICtrlCreateRadio("US", 10, -1, 40) Local $Rad_Intern = GUICtrlCreateRadio("International", 10, -1, 80) GUIStartGroup() Switch $iDef_Temp Case -1 GUICtrlSetState($Rad_Default, 1) Case 0 GUICtrlSetState($Rad_Intern, 1) Case Else GUICtrlSetState($Rad_US, 1) EndSwitch GUISetCoord(55, 140) Local $Btn_Go = GUICtrlCreateButton("Proceed", -1, -1, 60, 25) Local $Btn_Cncl = GUICtrlCreateButton("Cancel", 20, -1, 60, 25, 1) GUISetState() While 1 Local $hMsg = GUIGetMsg() Switch $hMsg Case -3, $Btn_Cncl GUIDelete() Return Case $Btn_Go If GUICtrlRead($in_Copies) <> $iMaxS Then $iMaxS = GUICtrlRead($in_Copies) IniWrite($ini, "Settings", "Keep Previous", $iMaxS) StringReplace($sPrevS, "|", "") Local $iTest = @Extended Local $iCount = $iMaxS - 1 If $iTest > $iCount Then Local $iRepl = $iTest - $iCount $iRepl = StringInStr($sPrevS, "|",0, $iRepl)+1 $sPrevS = StringMid($sPrevS,$iRepl) IniWrite($Ini, "Searches","List", $sPrevS) EndIf EndIf If GUICtrlRead($Rad_Default) = 1 Then $iDef_Temp = -1 ElseIf GUICtrlRead($Rad_US) = 1 Then $iDef_Temp = 1 Else $iDef_Temp = 0 EndIf If INIRead($ini, "Settings","Info", -1) <> $iDef_Temp Then _ IniWrite($ini, "Settings","Info", $iDef_Temp) GUIDelete() Return Case Else EndSwitch Wend EndFunc ;<==> _Opts() ; George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Mat Posted April 15, 2009 Author Posted April 15, 2009 (edited) Thanks as always GEOSoft I only noticed this now as I came to update the code, I managed to get it working (sortof) except the controls still move slightly and something goes wrong, despite setting the resize mode to dock all. heres mine - if any wants to see, will probably be updated to use GEOSofts method in a bit. CODE#include <GUIConstantsex.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> Opt("GUICoordMode", 1) Opt("GUIResizeMode", $GUI_DOCKALL) Global $bars = 45;based on score required for "strong" rating Global $grad_bars[$bars + 1] = [$bars] Global $pbOldValue = 0 $pbMeterLeft = 10 $pbMeterTop = 40 $pbMeterWidth = 420 $pbMeterHeight = 30 $BrGreen = 0x00FF00 $BrRed = 0xE71800 $start_Color = $BrGreen $target_color = $BrRed $barWidth = $pbMeterWidth / $bars $barLeft = $pbMeterLeft $value = 0 $hGUI = GUICreate("Password Tester", 440, 110, 200, 130) GUICtrlCreateLabel("Password:", 10, 12, 60, 20) $gcPWField = GUICtrlCreateInput("", 80, 10, 350, 20, $WS_VSCROLL, $WS_EX_CLIENTEDGE) $pBarMeter = GUICtrlCreateGraphic($pbMeterLeft, $pbMeterTop, $pbMeterWidth, $pbMeterHeight, $SS_SUNKEN) $gcStrength = GUICtrlCreateLabel("Strength:", 10, 80, 100, 20) $gcScore = GUICtrlCreateLabel("Score:", 170, 80, 100, 20) $PntsShow = GUICtrlCreateButton ("Show Points >>", 300, 80, 100, 20) ; Hidden becouse of GUI size $gcRTField = GUICtrlCreateEdit("", 10, 110, 400, 180, $ES_READONLY + $WS_VSCROLL, $WS_EX_CLIENTEDGE) For $bar = 1 To $bars $grad_bars[$bar] = GUICtrlCreateLabel("", $barLeft, $pbMeterTop, $barWidth+1, $pbMeterHeight) $barLeft += ($barWidth) Next For $i = 1 To $bars $target_color_str = _MakeGradLineColors($start_Color, $target_color, ($bars - $i));/2);$value - $i) GUICtrlSetBkColor($grad_bars[$i], $target_color_str) GUICtrlSetState($grad_bars[$i], $GUI_HIDE) Next GUISetState(@SW_SHOW) Local $a, $s = '' While 1 $msg = GUIGetMsg() Switch $msg Case $PntsShow If GUICtrlRead ($PntsShow) <> "<< HidePoints" Then GUICtrlSetData ($PntsShow, "<< HidePoints") WinMove ("Password Tester", "", Default, Default, 440, 300) Else GUICtrlSetData ($PntsShow, "Show Points >>") WinMove ("Password Tester", "", Default, Default, 440, 110) EndIf Case $GUI_EVENT_CLOSE Exit Case Else If GUICtrlRead($gcPWField) <> $s Then $s = GUICtrlRead($gcPWField) $a = testPassword($s) GUICtrlSetData($gcStrength, "Strength: " & $a[1]) GUICtrlSetData($gcScore, "Score: " & $a[0]) GUICtrlSetData($gcRTField, $a[2]) _pBarRefresh($a[0]) EndIf EndSwitch WEnd Func testPassword($passwd) Local $intScore = 0 Local $strVerdict = "weak" Local $strLog = "" Local $intPWlen = StringLen($passwd) ; PASSWORD LENGTH If ($intPWlen < 5) Then; length 4 or less $intScore += 3 $strLog &= "3 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 4 And $intPWlen < 8) Then; length between 5 and 7 $intScore += 6 $strLog &= "6 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 7 And $intPWlen < 16) Then; length between 8 and 15 $intScore += 12 $strLog &= "12 points for length (" & $intPWlen & ")\r\n" ElseIf ($intPWlen > 15) Then; length 16 or more $intScore += 18 $strLog &= "18 point for length (" & $intPWlen & ")\r\n" EndIf ; LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex) If StringRegExp($passwd, '[a-z]') Then;// [verified] at least one lower case letter $intScore += 1 $strLog &= "1 point for at least one lower case char\r\n" EndIf If StringRegExp($passwd, '[A-Z]') Then; // [verified] at least one upper case letter $intScore += 5 $strLog &= "5 points for at least one upper case char\r\n" EndIf ; NUMBERS If StringRegExp($passwd, '\d+') Then;// [verified] at least one number $intScore += 5 $strLog &= "5 points for at least one number\r\n" EndIf If StringRegExp($passwd, '(.*[0-9].*[0-9].*[0-9])') Then;// [verified] at least three numbers $intScore += 5 $strLog &= "5 points for at least three numbers\r\n" EndIf ; SPECIAL CHAR If StringRegExp($passwd, '[[:punct:]\x80-\xff]') Then;// [verified] at least one special character $intScore += 5 $strLog &= "5 points for at least one special char\r\n" EndIf If StringRegExp($passwd, '(.*[[:punct:]\x80-\xff].*[[:punct:]\x80-\xff])') Then $intScore += 5 $strLog &= "5 points for at least two special chars\r\n"; // [verified] at least two special characters EndIf ; COMBOS If StringRegExp($passwd, '([a-z].*[A-Z])|([A-Z].*[a-z])') Then;// [verified] both upper and lower case $intScore += 2 $strLog &= "2 combo points for upper and lower letters\r\n" EndIf If StringRegExp($passwd, '([a-zA-Z])/') And StringRegExp($passwd, '/([0-9])') Then;// [verified] both letters and numbers $intScore += 2 $strLog &= "2 combo points for letters and numbers\r\n" EndIf If StringRegExp($passwd, '([a-zA-Z0-9].*[[:punct:]\x80-\xff])|([[:punct:]\x80-\xff].*[a-zA-Z0-9])') Then $intScore += 2;// [verified] letters, numbers, and special characters $strLog &= "2 combo points for letters, numbers and special chars\r\n" EndIf ;Verdict If ($intScore < 16) Then $strVerdict = "very weak" ElseIf ($intScore > 15 And $intScore < 25) Then $strVerdict = "weak" ElseIf ($intScore > 24 And $intScore < 35) Then $strVerdict = "mediocre" ElseIf ($intScore > 34 And $intScore < 45) Then $strVerdict = "strong" Else $strVerdict = "stronger" EndIf Local $aArray[3] = [$intScore, $strVerdict, StringFormat($strLog) ] Return $aArray EndFunc;==>testPassword Func _pBarRefresh($pbValue) If $pbValue > $bars Then $pbValue = $bars If $pbValue < $pbOldValue Then For $i = $bars To ($pbValue + 1) Step - 1 GUICtrlSetState($grad_bars[$i], $GUI_HIDE) Sleep(1) Next EndIf If $pbValue > $pbOldValue Then For $i = 1 To $pbValue GUICtrlSetState($grad_bars[$i], $GUI_SHOW) Sleep(1) Next EndIf $pbOldValue = $pbValue ; EndIf Return EndFunc;==>_pBarRefresh Func _MakeGradLineColors($start_Color, $target_color, $i) Local $g_red = GetColorRed($start_Color) Local $g_green = GetColorGreen($start_Color) Local $g_blue = GetColorBlue($start_Color) Local $g_r_step = (GetColorRed($target_color) - $g_red) / $bars;$value;$cpc_grad_step Local $g_g_step = (GetColorGreen($target_color) - $g_green) / $bars;$value;$cpc_grad_step Local $g_b_step = (GetColorBlue($target_color) - $g_blue) / $bars;$value;$cpc_grad_step Return "0x" & StringFormat("%02X%02X%02X", $g_red + $g_r_step * $i, $g_green + $g_g_step * $i, $g_blue + $g_b_step * $i) EndFunc;==>_MakeGradLineColors ; The standard AutoIt UDF color functions ; re-named and here for convenience ; Func GetColorRed($nColor) Return BitAND(BitShift($nColor, 16), 0xff) EndFunc;==>GetColorRed Func GetColorGreen($nColor) Return BitAND(BitShift($nColor, 8), 0xff) EndFunc;==>GetColorGreen Func GetColorBlue($nColor) Return BitAND($nColor, 0xff) EndFunc;==>GetColorBlue Edited April 16, 2009 by mdiesel AutoIt Project Listing
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now