Jump to content
AlmarM

Password Generator

Recommended Posts

AlmarM

I improved my older password generator.

Global Const $CHR_AZ_LOW        = StringLower("abcdefghijklmnopqrstuvwxyz")
Global Const $CHR_AZ_UP        = StringUpper("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
Global Const $CHR_NUMBERS    = "0123456789"

Global $sUseCharacters = $CHR_AZ_LOW

$hWnd = GUICreate("Password Generator.", 460, 175)
GUICtrlCreateGroup("Options", 10, 10, 280, 75)
GUICtrlCreateLabel("Password length:", 20, 30)
$hPasswordLength = GUICtrlCreateInput(8, 130, 27, 40)
$hUpDown = GUICtrlCreateUpDown($hPasswordLength)
GUICtrlCreateLabel("Characters:", 20, 53)
$hCharacters = GUICtrlCreateCombo("a-z", 130, 50, 150, 20, 0x0003)
$hCurrentSequence = GUICtrlCreateLabel("Hover me to see your current sequence.", 10, 90, 280)
$hGenerate = GUICtrlCreateButton("Generate", 10, 110, 135, 25)
$hClearHistory = GUICtrlCreateButton("Clear history", 155, 110, 135, 25)
$hPassword = GUICtrlCreateInput("", 10, 145, 280, 20)
$hHistory = GUICtrlCreateEdit("", 300, 10, 150, 155, BitOR(0x0800, 0x0040, 0x00200000))

GUICtrlSetData($hCharacters, "A-Z|0-9|a-z, A-Z|a-z, 0-9|A-Z, 0-9|a-z, A-Z, 0-9|< User defined ... >", "a-z")
GUICtrlSetLimit($hUpDown, 99, 1)
GUICtrlSetTip($hCurrentSequence, $sUseCharacters)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $hCharacters
            $sRead = GUICtrlRead($hCharacters)
            If ($sRead == "a-z") Then
                $sUseCharacters = $CHR_AZ_LOW
            ElseIf ($sRead == "A-Z") Then
                $sUseCharacters = $CHR_AZ_UP
            ElseIf ($sRead == "0-9") Then
                $sUseCharacters = $CHR_NUMBERS
            ElseIf ($sRead == "a-z, A-Z") Then
                $sUseCharacters = $CHR_AZ_LOW & $CHR_AZ_UP
            ElseIf ($sRead == "a-z, 0-9") Then
                $sUseCharacters = $CHR_AZ_LOW & $CHR_NUMBERS
            ElseIf ($sRead == "A-Z, 0-9") Then
                $sUseCharacters = $CHR_AZ_UP & $CHR_NUMBERS
            ElseIf ($sRead == "a-z, A-Z, 0-9") Then
                $sUseCharacters = $CHR_AZ_LOW & $CHR_AZ_UP & $CHR_NUMBERS
            ElseIf ($sRead == "< User defined ... >") Then
                $sUseCharacters = InputBox("Password Generator.", "Enter a character sequence.", "abcABC123!@#", "", 200, 100)
            EndIf
            GUICtrlSetTip($hCurrentSequence, $sUseCharacters)

        Case $hGenerate
            $sPassword = _GeneratePassword(GUICtrlRead($hPasswordLength), $sUseCharacters)
            GUICtrlSetData($hPassword, $sPassword)
            GUICtrlSetData($hHistory, $sPassword & @CRLF, "|")

        Case $hClearHistory
            GUICtrlSetData($hHistory, "")
    EndSwitch
WEnd

Func _GeneratePassword($iLength, $sSequence)
    Local $sResult
    Local $aSplit = StringSplit($sSequence, "", 2)

    For $i = 1 To $iLength
        $sResult &= $aSplit[Random(0, UBound($aSplit) - 1, 1)]
    Next

    Return $sResult
EndFunc

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites
DarkAngel

@ Almar i wonder if we could use this utility ... in ur project ... Of course if u r in that is ;)

Share this post


Link to post
Share on other sites
AlmarM

Sure, just inform me. :)

Update me about the progress of your project ;)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites
trung0407

Also try to add some options such as :

- have at least x numbers

- have at least 1 capital letter

- start with capital letter

Share this post


Link to post
Share on other sites
AHRIMANSEFID

Very Good Code But Me Need Generator User + Password And Save text File.

Share this post


Link to post
Share on other sites
jchd

4-year old now...


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
AlmarM

Wow. :sweating:


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites
Page2PagePro

Thank you AlmarM for the inspiration.

I added UUID, Dictionary and other customizations.

Confirming and corrective feedback appreciated.

#cs
    [FileVersion]
#ce

;; ############################################################################
#NoTrayIcon
#Region
#AutoIt3Wrapper_UseX64=N
#AutoIt3Wrapper_icon=PadLock.ico
#AutoIt3Wrapper_res_fileversion=1.2.1.5
#AutoIt3Wrapper_Res_ProductVersion=1.2.1.5
://////=__=--
#AutoIt3Wrapper_res_legalcopyright=Page2PagePro.com
#AutoIt3Wrapper_res_language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_File_Add=WORDS_filtered.txt, rt_rcdata, TXT_WORDS
#AutoIt3Wrapper_Res_File_Add=M0nac0.ttf, rt_rcdata, TTF_MONACO
#EndRegion


;~ Revisions:
#cs
    1.0.0.0     2015-05-13
    - AlmarM:   https://www.autoitscript.com/forum/topic/120728-password-generator/
    1.1.0.0     2015-10-05
    - Added UUID (GUID is M$ version of UUID) version 4
    - https://en.wikipedia.org/wiki/Universally_unique_identifier
    - Changed _SETPOOL to Select
    - Added HasCharPool()
    - Added Arguments to ValidateMinimumLength()
    1.2.0.0     2016-09-06
    - Added Dictionary Search Tool and made default
    - https://svnweb.freebsd.org/csrg/share/dict/words?view=co
    1.2.0.5     2016-12-06
    - Added Unicode U+23B5 which *implies* using a   space as separator
    1.2.1.0     2016-12-08
    - words.txt --> WORDS_filtered_1.txt
    - 25,487 words starting
    - 1) Remove words with "dots"
    -   Notepad++:  Regular express; Uncheck matches newline; Check wrap around; Check Match case
    -   ^(.*)(\.)(.*)\n
    -   5 removed
    -   e.g
    -   i.e
    -   Ph.D
    -   U.S
    -   U.S.A
    - 2) Remove words with apostrophes
    -   Notepad++:  Regular express; Uncheck matches newline; Check wrap around; Check Match case
    -   ^(.*)(')(.*)\n
    -   104 removed
    -   ain't
    -   etc
    - 3) Remove proper nouns (1st letter capialized):
    -   Notepad++:  Regular express; Uncheck matches newline; Check wrap around; Check Match case
    -   ^([A-Z])(.*)\n
    -   4987 (4968) removed
    - 4) Remove short words (length 1 - 4 characters):
    -   ^[A-Za-z]{1,4}\n
    -   3108 (2466) removed
    - 5) Remove long words (length over 10 characters) = 2208 words:
    -   ^[A-Za-z]{11,}\n
    -   2208 (2049) removed
    - 14895 words remain
    1.2.1.5    2017-12-05
    - Grouped dependencies for publishing
#ce



Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

#include <GUIConstants.au3>
#include <FontConstants.au3>
;~ #include <Resources.au3>
#include "Resources.au3"
#include <Array.au3>
#include <ScrollBarConstants.au3>
#include <GUIEdit.au3>

Const $RES_TTF_MONACO = "M0nac0.ttf"
Global $sWordsFileName = "WORDS_filtered.txt"
;~ Create Dictionary Array
Global $WordsPool
If @Compiled Then
    _ResourceSaveToFile(@TempDir & "\" & $sWordsFileName, "TXT_WORDS", $RT_RCDATA, 0, 1)
    $WordsPool = @TempDir & "\" & $sWordsFileName
Else
    $WordsPool = ".\" & $sWordsFileName
EndIf
Global Const $WORDS = FileReadToArray($WordsPool)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the " & $sWordsFileName & " file. @error: " & @error) ; An error occurred reading the current script file.
    Exit
EndIf
FileDelete(@TempDir & "\" & $sWordsFileName)


Global Const $CHR_AZ_LOW = StringLower("abcdefghijklmnopqrstuvwxyz")
Global Const $CHR_AZ_UP = StringUpper("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
Global Const $CHR_AZ_LOW_HEX = StringLower("abcdef")
Global Const $CHR_AZ_UP_HEX = StringUpper("ABCDEF")
Global Const $CHR_NUMBERS = "0123456789"
Global Const $CHR_SPECIAL = "`~!@#$%^&*()-_=+[]{};:'" & '"' & "<>,./?\|"
Global Const $CHR_SPECIAL_DICT = "`~!@#$%^&()=[]{};:'" & '"' & "<>,/?\|"
Global $sUseCharacters = "WORDS + " & $CHR_NUMBERS & $CHR_SPECIAL_DICT
Global $hGUI, $hPasswordLength, $hPasswordLengthUpDown, $hCharacters, $hCurrentSequence
Global $hPasswordLengthLbl
Global $hWordQuantity, $hNumberQuantity, $hSymbolQuantity, $hCapitalizeFirst, $hWordSeparator
Global $hWordQuantityLbl, $hNumberQuantityLbl, $hSymbolQuantityLbl, $hCapitalizeFirstLbl, $hWordSeparatorLbl
Global $hGenerate, $hClearHistory, $hPassword, $hHistory
Global $hPasswordClip, $hHistoryClip
Global $hStatus, $hFont ;~ Status Bar Vars
Global $sRead, $sPassword
Global $iPasswordLength = 64
Global $sMinimumPattern ;~ http://stackoverflow.com/questions/19605150/regex-for-password-must-be-contain-at-least-8-characters-least-1-number-and-bot
Global $iMinimumLength

;~ Establish if Compiled or ran from SciTE
Global $ScriptName, $ScriptExt, $ScriptDir, $ScriptIniFull, $ScriptVersion, $ScriptRevised
$ScriptDir = @ScriptDir & "\"
$ScriptName = StringLeft(@ScriptName, StringLen(@ScriptName) - 4)
$ScriptIniFull = $ScriptDir & $ScriptName & ".ini"
If @Compiled = 1 Then
    $ScriptExt = ".exe"
;~  VERSION from Binary
    $ScriptVersion = FileGetVersion(@ScriptFullPath)
    $ScriptRevised = FileGetVersion(@ScriptFullPath, $FV_PRIVATEBUILD)
;~ When compiled extract Custom Font to Temp Folder
    _ResourceSaveToFile(@TempDir & "\" & $RES_TTF_MONACO, "TTF_MONACO", $RT_RCDATA, 0, 1)
    _WinAPI_AddFontResourceEx(@TempDir & "\" & $RES_TTF_MONACO, $FR_PRIVATE)
Else
    $ScriptExt = ".au3"
    $ScriptVersion = IniRead(@ScriptFullPath, "FileVersion", "#AutoIt3Wrapper_res_fileversion", "0.0.0.0")
;~  REVISED from script region text
    $ScriptRevised = IniRead(@ScriptFullPath, "FileVersion", "#AutoIt3Wrapper_Res_Field", "PrivateBuild|YYYY-MM-DD@HHMM")
    Local $aToken = StringSplit($ScriptRevised, "|")
    $ScriptRevised = $aToken[2]
;~ When ran for debugging use TTF in CommonFiles\tonts
    _WinAPI_AddFontResourceEx(".\" & $RES_TTF_MONACO, $FR_PRIVATE)
EndIf

CreateGUI("Password Generator v(" & $ScriptVersion & ")")
Loop()

;; ############################################################################






Func Loop()
    While 1
        Sleep(309)
    WEnd
EndFunc   ;==>Loop
;~ ____________________________________________________________________________
Func CreateGUI($sTitle)
;~  GUI
    $hGUI = GUICreate($sTitle, 775, 225 + 20) ;~ 175 + 20 for StatusBar
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

;~  GROUP
    GUICtrlCreateGroup("Options", 5, 5, 280, 125)

;~  Password Length
    $hPasswordLengthLbl = GUICtrlCreateLabel("Password length:", 10, 30)
    GUICtrlSetState(-1, 32 + 128)
    $hPasswordLength = GUICtrlCreateInput($iPasswordLength, 100, 27, 40)
    GUICtrlSetState(-1, 32 + 128)
    $hPasswordLengthUpDown = GUICtrlCreateUpdown($hPasswordLength)
    GUICtrlSetLimit(-1, 64, 1)
    GUICtrlSetState(-1, 32 + 128)

;~  Password Characters
    GUICtrlCreateLabel("Characters:", 10, 53)
    $hCharacters = GUICtrlCreateCombo("", 80, 50, 200, 20, 0x0003)
    GUICtrlSetData(-1, "a-z|A-Z|0-9|a-zA-Z|a-z0-9|A-Z0-9|a-zA-Z0-9|a-z0-9(min 1,1)|A-Z0-9(min 1,1)|a-zA-Z0-9(min 1,1,1)|a-zA-Z0-9<SPECIAL>(min 1,1,1,1)|DICTIONARY(min 1,1,1,1)|<HEX A-F0-9>|<10-Key Numpad 0-9/*-+>|UUIDv4(upper)|UUIDv4(lower)|< User defined ... >", "DICTIONARY(min 1,1,1,1)")
    GUICtrlSetOnEvent(-1, "_SETPOOL")

;~  Dictionary Options
    $hWordQuantityLbl = GUICtrlCreateLabel("Words:", 10, 75)
;~  GUICtrlSetState(-1, 32 + 128)
    $hWordQuantity = GUICtrlCreateCombo("", 52, 73, 35, 20, 0x0003)
;~  GUICtrlSetState(-1, 32 + 128)
    GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9", "2")

    $hNumberQuantityLbl = GUICtrlCreateLabel("Numbers:", 100, 75)
;~  GUICtrlSetState(-1, 32 + 128)
    $hNumberQuantity = GUICtrlCreateCombo("", 153, 73, 35, 20, 0x0003)
;~  GUICtrlSetState(-1, 32 + 128)
    GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9", "1")

    $hSymbolQuantityLbl = GUICtrlCreateLabel("Symbols:", 197, 75)
;~  GUICtrlSetState(-1, 32 + 128)
    $hSymbolQuantity = GUICtrlCreateCombo("", 245, 73, 35, 20, 0x0003)
;~  GUICtrlSetState(-1, 32 + 128)
    GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9", "1")

    $hCapitalizeFirstLbl = GUICtrlCreateLabel("Cap 1st?", 10, 99)
;~  GUICtrlSetState(-1, 32 + 128)
    $hCapitalizeFirst = GUICtrlCreateCheckbox("", 60, 96, 35, 20, 0x0003)
;~  GUICtrlSetState(-1, 32 + 128)
    GUICtrlSetState(-1, 1)

    $hWordSeparatorLbl = GUICtrlCreateLabel("Separator:", 100, 99)
;~  GUICtrlSetState(-1, 32 + 128)
    $hWordSeparator = GUICtrlCreateCombo("", 153, 96, 35, 20, 0x0003)
;~  GUICtrlSetState(-1, 32 + 128)
;~  http://www.fileformat.info/info/unicode/char/23b5/index.htm
;~  Unicode Character 'BOTTOM SQUARE BRACKET' (U+23B5)
    GUICtrlSetData(-1, " |-|.|*|_|+|" & ChrW(9141), " ")


;~  GENERATE
    $hGenerate = GUICtrlCreateButton("Generate", 5, 160, 135, 25)
    GUICtrlSetOnEvent(-1, "_GENERATE")

;~  CLEAR
    $hClearHistory = GUICtrlCreateButton("Clear history", 155, 160, 135, 25)
    GUICtrlSetOnEvent(-1, "_CLEAR")

;~  OUTPUT
    $hPassword = GUICtrlCreateInput("", 155, 197, 465, 22, $ES_CENTER)
    GUICtrlSetFont($hPassword, 9, 400, 0, "Monaco")

;~  HISTORY
    $hHistory = GUICtrlCreateEdit("", 295, 10, 475, 125, BitOR(0x0800, 0x0040, 0x00200000))
    ; Use monospaced Monaco font, size 9
    GUICtrlSetFont($hHistory, 9, 400, 0, "Monaco")

;~  CLIPBOARD
    $hPasswordClip = GUICtrlCreateButton("Copy ONE Clipboard", 5, 195, 135, 25)
    GUICtrlSetOnEvent(-1, "_CLIPBOARD_ONE")
    $hHistoryClip = GUICtrlCreateButton("Copy ALL Clipboard", 635, 195, 135, 25)
    GUICtrlSetOnEvent(-1, "_CLIPBOARD_ALL")

;~  TOOL TIP
    $hCurrentSequence = GUICtrlCreateLabel("Hover me to see your current sequence.", 10, 140, 280, 15, 0x01)
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, 0xC0DCC0)
    GUICtrlSetTip($hCurrentSequence, $sUseCharacters)

;~  STATUS BAR
    $hStatus = GUICtrlCreateLabel("Page2PagePro.com", 0, 225, 775, 20, $SS_SUNKEN + $SS_CENTER)
    GUICtrlSetFont(-1, 9, 400, "", "Monaco")

;~  SHOW GUI
    GUISetState(@SW_SHOW)
EndFunc   ;==>CreateGUI
;~ ____________________________________________________________________________
Func _exit()
    _WinAPI_DeleteObject($hFont)
    GUIDelete()
    ConsoleWrite("Exit" & @CRLF)
    Exit
EndFunc   ;==>_exit
;~ ____________________________________________________________________________
Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), 1) = 1
EndFunc   ;==>_IsChecked
;~ ____________________________________________________________________________
Func CapitalizeFirst($s)
    Return StringUpper(StringLeft($s, 1)) & StringMid($s, 2)
EndFunc   ;==>CapitalizeFirst
;~ ____________________________________________________________________________
Func StringJoin(Const ByRef $avArray, $sDelim_Item = "|", $iStart_Row = -1, $iEnd_Row = -1, $sDelim_Row = @CRLF, $iStart_Col = -1, $iEnd_Col = -1)
    Return _ArrayToString($avArray, $sDelim_Item, $iStart_Row, $iEnd_Row, $sDelim_Row, $iStart_Col, $iEnd_Col)
EndFunc   ;==>StringJoin
;~ ____________________________________________________________________________
Func GenerateDictionaryPassword()
    Local $iWordsToUse = GUICtrlRead($hWordQuantity)
    Local $bAlwaysCapitalizeFirstLetter = _IsChecked($hCapitalizeFirst)
    Local $iNumbersToUse = GUICtrlRead($hNumberQuantity)
    Local $iSymbolsToUse = GUICtrlRead($hSymbolQuantity)
    Local $aPassword[0]
    Local $sTemp, $iLocation

;~  Select Two Random Words and add to Empty Array
    For $j = 1 To $iWordsToUse
        $sTemp = $WORDS[Random(0, UBound($WORDS) - 1, 1)]
        If $bAlwaysCapitalizeFirstLetter Then $sTemp = CapitalizeFirst($sTemp)
        _ArrayAdd($aPassword, $sTemp)
    Next

;~  If Numbers are to be used, add them between the two words (for now)
    For $j = 1 To $iNumbersToUse
;~      $iLocation = 2
        $iLocation = Random(0, UBound($aPassword), 1)
        ConsoleWrite($iLocation & " " & UBound($aPassword) & @CR)
        $sTemp = Random(0, 9, 1)
        If $iLocation = UBound($aPassword) Then
            _ArrayAdd($aPassword, $sTemp)
        Else
            _ArrayInsert($aPassword, $iLocation, $sTemp)
        EndIf
    Next

;~  If Symbols are to be used, Randomlly insert into array
    Local $aSpecial = StringSplit($CHR_SPECIAL_DICT, "", 2)
    For $j = 1 To $iSymbolsToUse
        $iLocation = Random(0, UBound($aPassword), 1)
        $sTemp = $aSpecial[Random(0, UBound($aSpecial) - 1, 1)]
        If $iLocation = UBound($aPassword) Then
            _ArrayAdd($aPassword, $sTemp)
        Else
            _ArrayInsert($aPassword, $iLocation, $sTemp)
        EndIf
    Next

;~  Add Separator if combo isn't "null" (It's actually a SPACE)
    If StringCompare(GUICtrlRead($hWordSeparator), " ") = 0 Then
;~      Do Nothing
    Else
        If StringCompare(GUICtrlRead($hWordSeparator), ChrW(9141)) = 0 Then
;~          MsgBox("","",GUICtrlRead($hWordSeparator))
            $sTemp = StringJoin($aPassword, " _")
            $aPassword = StringSplit($sTemp, "_", 2)
        Else
            $sTemp = StringJoin($aPassword, GUICtrlRead($hWordSeparator) & " ")
            $aPassword = StringSplit($sTemp, " ", 2)
        EndIf
    EndIf
    Return $aPassword
EndFunc   ;==>GenerateDictionaryPassword
;~ ____________________________________________________________________________
Func _GENERATE()

;~  Deselect History and scroll to end to leiminate overwiting highlighed/selected
    Local $iEnd = StringLen(GUICtrlRead($hHistory))
    _GUICtrlEdit_SetSel($hHistory, $iEnd, $iEnd)
    _GUICtrlEdit_Scroll($hHistory, $SB_SCROLLCARET)

    If StringCompare(GUICtrlRead($hCharacters), "DICTIONARY(min 1,1,1,1)") = 0 Then
        Local $aPassword = GenerateDictionaryPassword()
;~      _ArrayDisplay($aPassword)
        $sPassword = StringJoin($aPassword, "")
    Else
        If ValidateMinimumLength($iMinimumLength, GUICtrlRead($hPasswordLength)) And HasCharPool($sUseCharacters) Then
            $iPasswordLength = GUICtrlRead($hPasswordLength)
            $sPassword = _GeneratePassword($iPasswordLength, $sUseCharacters)
        EndIf
    EndIf
    GUICtrlSetData($hPassword, $sPassword)
    GUICtrlSetData($hHistory, $sPassword & @CRLF, "|")
EndFunc   ;==>_GENERATE
;~ ____________________________________________________________________________
Func _CLEAR()
    GUICtrlSetData($hHistory, "")
EndFunc   ;==>_CLEAR
;~ ____________________________________________________________________________
Func _SETPOOL()
    $sMinimumPattern = ""
    $iMinimumLength = 0
    $sRead = GUICtrlRead($hCharacters)
    ConsoleWrite($sRead & @CR)

;~  WARNING: Switch statements are case-insensitive.
;~  Select statements are care-sensitive
    GUICtrlSetState($hPasswordLengthLbl, 16 + 64)
    GUICtrlSetState($hPasswordLength, 16 + 64)
    GUICtrlSetState($hPasswordLengthUpDown, 16 + 64)
    GUICtrlSetState($hWordQuantity, 32 + 128)
    GUICtrlSetState($hNumberQuantity, 32 + 128)
    GUICtrlSetState($hSymbolQuantity, 32 + 128)
    GUICtrlSetState($hCapitalizeFirst, 32 + 128)
    GUICtrlSetState($hWordQuantityLbl, 32 + 128)
    GUICtrlSetState($hNumberQuantityLbl, 32 + 128)
    GUICtrlSetState($hSymbolQuantityLbl, 32 + 128)
    GUICtrlSetState($hCapitalizeFirstLbl, 32 + 128)

    Select
        Case $sRead == "a-z"
            $sUseCharacters = $CHR_AZ_LOW
        Case $sRead == "A-Z"
            $sUseCharacters = $CHR_AZ_UP
        Case $sRead == "0-9"
            $sUseCharacters = $CHR_NUMBERS
        Case $sRead == "a-zA-Z"
            $sUseCharacters = $CHR_AZ_LOW & $CHR_AZ_UP
        Case $sRead == "a-z0-9"
            $sUseCharacters = $CHR_AZ_LOW & $CHR_NUMBERS
        Case $sRead == "A-Z0-9"
            $sUseCharacters = $CHR_AZ_UP & $CHR_NUMBERS
        Case $sRead == "a-zA-Z0-9"
            $sUseCharacters = $CHR_AZ_LOW & $CHR_AZ_UP & $CHR_NUMBERS
        Case $sRead == "a-z0-9(min 1,1)"
            $sUseCharacters = $CHR_AZ_LOW & $CHR_NUMBERS
            $sMinimumPattern = "(?=.*[a-z])(?=.*[0-9])"
            $iMinimumLength = 2
        Case $sRead == "A-Z0-9(min 1,1)"
            $sUseCharacters = $CHR_AZ_UP & $CHR_NUMBERS
            $sMinimumPattern = "(?=.*[A-Z])(?=.*[0-9])"
            $iMinimumLength = 2
        Case $sRead == "a-zA-Z0-9(min 1,1,1)"
            $sUseCharacters = $CHR_AZ_LOW & $CHR_AZ_UP & $CHR_NUMBERS
            $sMinimumPattern = "(?=.*[a-z])(?=.*[A-Z])(?=.*\d)"
            $iMinimumLength = 3
        Case $sRead == "a-zA-Z0-9<SPECIAL>(min 1,1,1,1)"
            $sUseCharacters = $CHR_AZ_LOW & $CHR_AZ_UP & $CHR_NUMBERS & $CHR_SPECIAL
            $sMinimumPattern = "(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W])"
            $iMinimumLength = 4
        Case $sRead == "DICTIONARY(min 1,1,1,1)"
            $sUseCharacters = "WORDS + " & $CHR_NUMBERS & $CHR_SPECIAL_DICT
            GUICtrlSetState($hPasswordLengthLbl, 32 + 128)
            GUICtrlSetState($hPasswordLength, 32 + 128)
            GUICtrlSetState($hPasswordLengthUpDown, 32 + 128)
            GUICtrlSetState($hWordQuantity, 16 + 64)
            GUICtrlSetState($hNumberQuantity, 16 + 64)
            GUICtrlSetState($hSymbolQuantity, 16 + 64)
            GUICtrlSetState($hCapitalizeFirst, 16 + 64)
            GUICtrlSetState($hWordQuantityLbl, 16 + 64)
            GUICtrlSetState($hNumberQuantityLbl, 16 + 64)
            GUICtrlSetState($hSymbolQuantityLbl, 16 + 64)
            GUICtrlSetState($hCapitalizeFirstLbl, 16 + 64)
        Case $sRead == "<HEX A-F0-9>"
            $sUseCharacters = $CHR_AZ_UP_HEX & $CHR_NUMBERS
        Case $sRead == "<10-Key Numpad 0-9/*-+>"
            $sUseCharacters = $CHR_NUMBERS & "/*-+"
        Case $sRead == "UUIDv4(upper)"
;~          $sUseCharacters = $CHR_AZ_UP_HEX & $CHR_NUMBERS
;~          http://stackoverflow.com/questions/6223185/php-preg-match-uuid-v4
;~          $sMinimumPattern = "[A-F0-9]{8}-[A-F0-9]{4}-4[A-F0-9]{3}-(8|9|A|B)[A-F0-9]{3}-[A-F0-9]{12}"
;~          $iMinimumLength = 32
            $sUseCharacters = $CHR_AZ_UP_HEX & $CHR_NUMBERS
            GUICtrlSetState($hPasswordLengthLbl, 32 + 128)
            GUICtrlSetState($hPasswordLength, 32 + 128)
            GUICtrlSetState($hPasswordLengthUpDown, 32 + 128)
        Case $sRead == "UUIDv4(lower)"
            $sUseCharacters = $CHR_AZ_LOW_HEX & $CHR_NUMBERS
            GUICtrlSetState($hPasswordLengthLbl, 32 + 128)
            GUICtrlSetState($hPasswordLength, 32 + 128)
            GUICtrlSetState($hPasswordLengthUpDown, 32 + 128)
        Case $sRead == "< User defined ... >"
            $sUseCharacters = InputBox("Password Generator", "Enter a character sequence.", $CHR_SPECIAL, "", 200, 130)
        Case Else
            MsgBox(16, "ERROR", "Selected POOL not understood.")
            $sUseCharacters = ""
    EndSelect
    GUICtrlSetTip($hCurrentSequence, $sUseCharacters)

    ValidateMinimumLength($iMinimumLength, GUICtrlRead($hPasswordLength))
EndFunc   ;==>_SETPOOL
;~ ____________________________________________________________________________
Func ValidateMinimumLength($iMinimumLength, $iTest)
    If $iTest < $iMinimumLength Then
        MsgBox(64, "WARNING!", "The Pool selected requires " & ($iMinimumLength - $iTest) _
                 & " more characters to your length. Please change.")
        Return False
    EndIf
    Return True
EndFunc   ;==>ValidateMinimumLength
;~ ____________________________________________________________________________
Func HasCharPool($sUseCharacters)
    If $sUseCharacters = "" Then
        MsgBox(16, "ERROR", "Character POOL is empty")
        Return False
    EndIf
    Return True
EndFunc   ;==>HasCharPool
;~ ____________________________________________________________________________
;Version 4 UUID generator
; credits goes to mimec (http://php.net/uniqid#69164)
;~ https://www.autoitscript.com/forum/topic/134387-version-4-uuid-generator/
Func uuid($strCase = "lower")
    Local $strUUID = StringFormat('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', _
            Random(0, 0xffff), Random(0, 0xffff), _
            Random(0, 0xffff), _
            BitOR(Random(0, 0x0fff), 0x4000), _
            BitOR(Random(0, 0x3fff), 0x8000), _
            Random(0, 0xffff), Random(0, 0xffff), Random(0, 0xffff) _
            )
    Return (StringUpper($strCase) = "UPPER" ? StringUpper($strUUID) : $strUUID)
EndFunc   ;==>uuid
;~ ____________________________________________________________________________
Func _GeneratePassword($iLength, $sSequence)
    Local $sResult, $bPass
    Local $aSplit = StringSplit($sSequence, "", 2)

    If StringLeft($sRead, 6) = "UUIDv4" Then
        $sResult = uuid(StringMid($sRead, 8, 5))
    Else
        Do
            $sResult = ""
            $bPass = False
            For $i = 1 To $iLength
                $sResult &= $aSplit[Random(0, UBound($aSplit) - 1, 1)]
            Next
            If StringRegExp($sResult, $sMinimumPattern) Then $bPass = True
            ConsoleWrite("+ " & $bPass & " ... " & $sResult & @CR)
        Until $bPass
    EndIf

    Return $sResult
EndFunc   ;==>_GeneratePassword
;~ ____________________________________________________________________________
Func _GUICtrlStatusBar_SetFont($hWnd, $iHeight = 15, $iWeight = 400, $iFontAtrributes = 0, $sFontName = "Arial")
    $hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, $iWeight, BitAND($iFontAtrributes, 2), BitAND($iFontAtrributes, 4), _
            BitAND($iFontAtrributes, 8), $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _
            $DEFAULT_QUALITY, 0, $sFontName)

    _SendMessage($hWnd, $WM_SETFONT, $hFont, 1)
EndFunc   ;==>_GUICtrlStatusBar_SetFont
;~ ____________________________________________________________________________
Func _CLIPBOARD_ONE()
    ClipPut(GUICtrlRead($hPassword))
EndFunc   ;==>_CLIPBOARD_ONE
;~ ____________________________________________________________________________
Func _CLIPBOARD_ALL()
    ClipPut(GUICtrlRead($hHistory))
EndFunc   ;==>_CLIPBOARD_ALL
;~ ____________________________________________________________________________

 

 

passwordGenerator_v1.2.1.5.zip

Edited by Page2PagePro
  • Like 2

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

×