Jump to content
Sign in to follow this  
crashdemons

Password Checker

Recommended Posts

crashdemons

I'm sure that other users have made similar scripts before this.

- however, I was asked by someone to create one to simulate the output of this webpage as much as possible:

Microsoft - Password checker

This script should use the same rules (based on testing) as Microsoft's checker to determine strength.

Please notify me if any discrepancies occur.

The main function of this script is does not attempt to be perfect but rather try to match the Microsoft page.

However, I have included a parameter to allow several different options as well as functions to include simple GUI controls for output.

Screenshot of script compared to Microsoft's checker:

Posted Image

Script:

#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt('GUIOnEventMode',1)
Global $lTxt = ''
Global $hGUI = GUICreate('Password Checker', 208, 80)
GUISetOnEvent(-3,'GUI_Exit')
Global $cInp = GUICtrlCreateInput('', 0, 0, 208, 20, $ES_PASSWORD)
Global $aPWC1 = _GUICtrlCreatePasswordCheck(0, 20, 208, 20)
Global $aPWC2 = _GUICtrlCreatePasswordCheck(0, 40, 25, 20, False, True, $WS_BORDER)
GUISetState()

While 1
    Local $nTxt = GUICtrlRead($cInp)
    If $lTxt <> $nTxt Then
        Local $iStr = _PasswordGetStrength($nTxt)
        _GUICtrlSetPasswordCheck($aPWC1, $iStr, True)
        _GUICtrlSetPasswordCheck($aPWC2, $iStr, False)
        $lTxt = $nTxt
    EndIf
    Sleep(300)
WEnd

#Region Functions

Func GUI_Exit()
    Exit
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _PasswordGetStrength
; Description ...: Checks the strength of an input password
; Syntax.........: _PasswordGetStrength($sPassword, $iMaxLength = 64, $fCase = True, $fSymbols = True)
; Parameters ....: $sPassword  - The password to be checked.
;                  $iMaxLength - The maximum length of an input password
;                  $fCase      - The boolean value indicating whether the password is case-sensitive.
; Return values .: Success - Returns an integer from 1 to 4 indicating password strength
;                  Failure - Returns 0 and sets @ERROR to:
;                  |0 - No error
;                  |1 - Password is blank
;                  |2 - MaxLength parameter is invalid
;                  |3 - Password length is above the MaxLength
; Author ........: Crash Daemonicus <crashenator at gmail dot com>
; Modified.......:
; Remarks .......: This function does not attempt to be perfect but simulates this webpage's output:
;                  |http://www.microsoft.com/protect/yourself/password/checker.mspx
; ===============================================================================================================================

Func _PasswordGetStrength($sPassword, $iMaxLength = 64, $fCase = True)
    Local $iReturn = 0, $iError = 0, $iLength = StringLen($sPassword)
    ;validate parameters
    If $iLength < 1 Then $iError = 1
    If $iMaxLength < 1 Then $iError = 2
    If $iLength > $iMaxLength Then $iError = 3
    ;if there were no errors, calculate password strength
    If $iError = 0 Then
        $iReturn = 1; all passwords start weak
        If $iLength > 7 Then; Passwords under 8 chars in length are always weak (See Microsoft's Password Checker)
            ; validated characters are A-Z,a-z,0-9, and punctuation
            Local $fLower = StringRegExp($sPassword, '[a-z]'), $fUpper = StringRegExp($sPassword, '[A-Z]'), $fNumeric = StringRegExp($sPassword, '\d')
            Local $fSymbol = StringRegExp($sPassword, '[[:punct:]]')
            Local $iLimit = 2
            If $fCase Then $iLimit = 3
            If $fNumeric And ($fUpper Or $fLower) Then $iReturn += 1; alphanumeric passwords add a point
            If $fSymbol And ($fUpper Or $fLower Or $fNumeric) Then $iReturn += 1; symbol + other validated chars adds a point
            If $fCase And $fLower And $fUpper Then $iReturn += 1; letter case changes add a point if passwords are case sensitive
            If $iReturn > $iLimit Then $iReturn = $iLimit; max Strength limit unless 14 chars long
            If $iReturn = $iLimit And $iLength > 13 Then $iReturn += 1; Best if Case-sense; Strong if not.
        EndIf
    EndIf
    SetError($iError)
    Return $iReturn
EndFunc   ;==>_PasswordGetStrength



Func _GUICtrlCreatePasswordCheck($iX, $iY, $iWidth = 210, $iHeight = 20, $fText = True, $fCase = True, $iStyle = 4097, $iExStyle = -1)
    Local $iSections = 3
    Local $iSecWidth
    If $fCase Then $iSections = 4
    Local $aControls[$iSections]
    $iSecWidth = Int($iWidth / $iSections)
    For $iSection = 0 To $iSections - 1
        $aControls[$iSection] = GUICtrlCreateLabel('', $iX + ($iSection * $iSecWidth), $iY, $iSecWidth, $iHeight, $iStyle, $iExStyle)
    Next
    _GUICtrlSetPasswordCheck($aControls, 0, $fText)
    Return $aControls
EndFunc   ;==>GUICtrlCreatePasswordCheck
Func _GUICtrlSetPasswordCheck(ByRef $aControls, $iStrength = 0, $fText = True, $iBackColor = 0xdfdfdf, $iForeColor = 0x000000)
    Local $Control
    Local $iSections = UBound($aControls)
    $iStrength = Int($iStrength)
    If $iStrength < 0 Or $iStrength > 4 Then Return 0
    Local $aStrengthText[5] = ['Not rated', 'Weak', 'Medium', 'Strong', 'Best']
    Local $aStrengthColor[5] = [$iBackColor, 0xff0000, 0xffcf00, 0x00af00, 0x00af00]
    For $iSection = 1 To $iSections
        Local $Control = $aControls[$iSection - 1]
        If $iSection <= $iStrength Then
            GUICtrlSetBkColor($Control, $aStrengthColor[$iStrength])
        Else
            GUICtrlSetBkColor($Control, $iBackColor)
        EndIf
        If $iSection = $iStrength Or ($iSection = 2 And $iStrength = 0) Then
            If $iStrength = 0 Then
                GUICtrlSetColor($Control, 0x5f5f5f)
                GUICtrlSetFont($Control, 8.5, 400)
            Else
                GUICtrlSetColor($Control, $iForeColor)
                GUICtrlSetFont($Control, 8.5, 700)
            EndIf
            If $fText Then GUICtrlSetData($Control, $aStrengthText[$iStrength])
        Else
            GUICtrlSetData($Control, '')
        EndIf
    Next
    Return 1
EndFunc   ;==>GUICtrlSetPasswordCheck

#EndRegion Functions

Enjoy.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
crashdemons

Kastout's example is quite good

- I didn't see a visual output though, which would have been nice.

- EDIT: The edit posted by ResNullius was good for visuals ^_^

Notes: had to add constants files to either.

However, ResNullius' edit gives a green rating to "password123456789" while Microsoft's checker will give a green to "abcd_123"

Guess you can't catch every "easy" password.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

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  

×