WeMartiansAreFriendly Posted September 28, 2007 Share Posted September 28, 2007 I found this script and thought it was pretty slick so I ported the code into Autoit, and made a simple gui for it. Enjoy!expandcollapse popup;http://www.geekwisdom.com/dyn/passwdmeter #include <GUIConstants.au3> $hGUI = GUICreate("Password Tester", 421, 370, 192, 125) GUICtrlCreateLabel("Password:", 14, 17, 53, 17) $gcPWField = GUICtrlCreateEdit("", 14, 39, 390, 76, $WS_VSCROLL, $WS_EX_CLIENTEDGE) $gcStrength = GUICtrlCreateLabel("Strength:", 16, 144, 100, 17) $gcScore = GUICtrlCreateLabel("Score:", 153, 144, 100, 17) $gcRTField = GUICtrlCreateEdit("", 14, 170, 393, 178, $ES_READONLY+$WS_VSCROLL, $WS_EX_CLIENTEDGE) GUISetState(@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]) 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,'.[!,@,#,$,%,^,&,*,?,_,~]') 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 $aArray Endfunc Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Skizmata Posted September 29, 2007 Share Posted September 29, 2007 Very cool, I like and can learn from! Good work. AutoIt changed my life. Link to comment Share on other sites More sharing options...
icadea Posted September 29, 2007 Share Posted September 29, 2007 thanks Link to comment Share on other sites More sharing options...
JustinReno Posted September 29, 2007 Share Posted September 29, 2007 Its cool; I like how it tells and reconizes that you put a special character in like capital letters, puncuation, and numbers. Nice Work! Link to comment Share on other sites More sharing options...
gseller Posted September 29, 2007 Share Posted September 29, 2007 Pretty Cool, do you know of any documentation for converting javascript to au3? I have some javascripts I would like to convert. Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted September 29, 2007 Author Share Posted September 29, 2007 Pretty Cool, do you know of any documentation for converting javascript to au3? I have some javascripts I would like to convert.I mainly use this website for referencing. Thanks for the feedback, guys! Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
gseller Posted September 29, 2007 Share Posted September 29, 2007 I mainly use this website for referencing. Thanks for the feedback, guys! This is a great website for javascript. I have not found any good resourses for converting to autoit.Thanks Link to comment Share on other sites More sharing options...
JSunn Posted September 29, 2007 Share Posted September 29, 2007 Very nice work! Link to comment Share on other sites More sharing options...
ResNullius Posted September 29, 2007 Share Posted September 29, 2007 (edited) Here's my take, with a colourized indicator of the password qualityNOTE: the colour gradient routines are straight from corz's "color pickin chooser" (which, if you haven't played with it yet, is very cool)expandcollapse popup;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 <GUIConstants.au3> Global $bars = 45 ;based on score required for "strong" rating Global $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) 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 $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, '.[!,@,#,$,%,^,&,*,?,_,~]') 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 $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 ;==>GetColorBlueEdit: speilinz mistokeEdit: fixed gap between meter bars; now nice & smooth Edited September 30, 2007 by ResNullius Link to comment Share on other sites More sharing options...
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