Jump to content

InputBox for setting a password? (HELP !?)


Recommended Posts

Hi all,

I am trying to use an InputBox to request a password from the user of My app. (not asking for the password to gain access, but actually set the password which will be used later on in My script).

Everything is working well, My app. can 'read' whatever password is entered, and it works fine.

My problem is this,

I want to force the user to create 'strong' passwords. I want to dictate a minimum length, and force the use of upper & lower case characters, numbers and special charaters too.

In an ideal world, I would also like the continue/next button to be disabled until the password criteria have been met, but this is less important (a simple error box after the button is pressed would suffice).

From what I can see, the standard options for the InputBox only force a mandatory entry, and a maximum length? (and a character mask).

I haven't posted any code because I'm using the standard code supplied in the examples, so I didn't see any point in posting it.

Can anyone help me please?...

This is the very last 'sub-project' I have to finish in order to complete the entire project (which I have been working on for weeks now).

Thanks

Link to comment
Share on other sites

try reading about this commands in help file and start testing them

GUICreate to create gui

GUICtrlCreateInput to make where user will tupe password

GUICtrlCreateButton to create buttons

StringLen to see how long string is

StringInStr to see if it contains numbers 1234567890 or space " " or something other

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Here's an example I came up with. It doesn't check for multiple instances of characters, but it will check for everything else. Enjoy!

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

Global $bOk = False, $bPass2 = False, $bStrong = False, $bInPass1Changed = False, $bInPass2Changed = False

#Region ### START Koda GUI section ### Form=
$guPass = GUICreate("Password Validation", 298, 163, 284, 161)
GUICtrlCreateLabel("Enter password:", 8, 32, 90, 17, $SS_RIGHT)
GUICtrlCreateLabel("Confirm password:", 8, 64, 90, 17, $SS_RIGHT)
$inPass1 = GUICtrlCreateInput("", 104, 32, 177, 21, $ES_PASSWORD)
$inPass2 = GUICtrlCreateInput("", 104, 64, 177, 21, $ES_PASSWORD)
GUICtrlSetState(-1, $GUI_DISABLE)
$lbStrong = GUICtrlCreateLabel("Password does NOT meet complexity requirements", 8, 96, 284, 17, $SS_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0xFF0000)
$btOk = GUICtrlCreateButton("OK", 112, 128, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $btOk
            MsgBox(64, "Password Validator", "Passwords match and meet complexity standards" & @CRLF & _
              "Password: " & GUICtrlRead($inPass1) & @CRLF & "Confirmed: " & GUICtrlRead($inPass2))
            Exit
        Case $bInPass1Changed
            If Not $bStrong Then
                If _ValidatePasswordStrength(GUICtrlRead($inPass1)) Then
                    $bStrong = True
                    GUICtrlSetData($lbStrong, "Password meets complexity requirements")
                    GUICtrlSetBkColor($lbStrong, 0x00FF00)
                    GUICtrlSetState($inPass2, $GUI_ENABLE)
                EndIf
            Else
                If Not _ValidatePasswordStrength(Guictrlread($inPass1)) Then
                    $bStrong = False
                    GUICtrlSetData($lbStrong, "Password does NOT meet complexity requirements")
                    GUICtrlSetBkColor($lbStrong, 0xFF0000)
                    GUICtrlSetData($inPass2, "")
                    GUICtrlSetState($inPass2, $GUI_DISABLE)
                EndIf
            EndIf
            $bInPass1Changed = False
        Case $bInPass2Changed
            If Not $bPass2 And $bStrong Then
                If GUICtrlRead($inPass1) == GUICtrlRead($inPass2) Then
                    $bPass2 = True
                    GUICtrlSetState($btOk, $GUI_ENABLE)
                EndIf
            Else
                If GUICtrlRead($inPass1) <> GUICtrlRead($inPass2) Or Not $bStrong Then
                    $bPass2 = False
                    GUICtrlSetState($btOk, $GUI_DISABLE)
                EndIf
            EndIf
            $bInPass2Changed = False
    EndSelect
WEnd

Func _ValidatePasswordStrength ($szPass, $nPassMinLength=8, $nPassLowerChars=2, $nPassUpperChars=2, $nPassNumbers=2, $nPassSpecialChars=2)
    Local $arResult

    ; Check for minimum length requirement
    If StringLen($szPass) < $nPassMinLength Then Return False
    
    ; Check for minimum lower case characters requirement
    If $nPassLowerChars > 0 Then
        $arResult = StringRegExp($szPass, "[a-z]", 3)
        Switch @error
            Case 0
                If UBound($arResult) < $nPassLowerChars Then Return False
            Case Else
                Return False
        EndSwitch
    EndIf
    
    ; Check for minimum upper case characters requirement
    If $nPassUpperChars > 0 Then
        $arResult = StringRegExp($szPass, "[A-Z]", 3)
        Switch @error
            Case 0
                If UBound($arResult) < $nPassUpperChars Then Return False
            Case Else
                Return False
        EndSwitch
    EndIf
    
    ; Check for minimum number characters requirement
    If $nPassNumbers > 0 Then
        $arResult = StringRegExp($szPass, "[0-9]", 3)
        Switch @error
            Case 0
                If UBound($arResult) < $nPassNumbers Then Return False
            Case Else
                Return False
        EndSwitch
    EndIf
    
    ; Check for minimum special characters requirement
    If $nPassSpecialChars > 0 Then
        $arResult = StringRegExp($szPass, "[^0-9|A-Z|a-z]", 3)
        Switch @error
            Case 0
                If UBound($arResult) < $nPassSpecialChars Then Return False
            Case Else
                Return False
        EndSwitch
    EndIf
    
    Return True
EndFunc

Func _WM_COMMAND ($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)
    Switch $hWndFrom
        Case GUICtrlGetHandle($inPass1)
            If $iCode = $EN_UPDATE Then $bInPass1Changed = True
        Case GUICtrlGetHandle($inPass2)
            If $iCode = $EN_UPDATE Then $bInPass2Changed = True
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>_WADAP_WM_COMMAND
Edited by zorphnog
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...