Page 1 sur 1

[Ex] Génération d'un mot de passe aléatoire

Posté : jeu. 17 avr. 2008 15:04
par Max5
Voilà un petit script que j'ai mit au point que j'ai nommé PassGenerator (pas très original ^^) qui génère un mot de passe aléatoire de 3 à 10 caractères avec des lettres majuscules et/ou minuscules et/ou des chiffres.

Code : Tout sélectionner

;~ Nom : PassGenerator
;~ Version : 1.0
;~ Auteur : Max5
;~ Version d'AutoIt : 3.2.10.0

#include <GUIConstants.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

$PassGenerator_GUI = GUICreate("PassGenerator v1.0", 263, 192, 193, 125)
$Label1 = GUICtrlCreateLabel("Générer un mot de passe de ", 8, 16, 141, 17)
$NbrChar = GUICtrlCreateCombo("", 149, 13, 41, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "3|4|5|6|7|8|9|10")
$Label2 = GUICtrlCreateLabel("caractères.", 194, 16, 57, 17)
$MajChar = GUICtrlCreateCheckbox("Avec des lettres majuscules (A-Z)", 8, 48, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$MinChar = GUICtrlCreateCheckbox("Avec des lettres minuscules (a-z)", 8, 72, 177, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$ChfrChar = GUICtrlCreateCheckbox("Avec des chiffres (0 - 9)", 8, 96, 129, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$GenerationInput = GUICtrlCreateInput("", 96, 135, 145, 28, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetLimit(-1, 10)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Generate = GUICtrlCreateButton("Générer", 8, 135, 75, 27, 0)
$MajList = GUICtrlCreateList("", 176, 112, 25, 6)
GUICtrlSetData(-1, "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z")
GUICtrlSetState(-1, $GUI_HIDE)
$MinList = GUICtrlCreateList("", 209, 86, 25, 6)
GUICtrlSetData(-1, "a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z")
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    
    If $msg = $GUI_EVENT_CLOSE Then Exit
    
    
    If $msg = $Generate Then
        If GUICtrlRead($NbrChar) <> "" Then
            If GUICtrlRead($MajChar) = 1 Or GUICtrlRead($MinChar) = 1 Or GUICtrlRead($ChfrChar) = 1 Then
                GUICtrlSetData($GenerationInput, "")
                $De0a9 = _ArrayCreate("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
                For $_pg = 0 To GUICtrlRead($NbrChar) - 1
                    If GUICtrlRead($MajChar) = 1 Then
                        $CapsChar = _GUICtrlListBox_GetText($MajList, Random(0, 25, 1))
                    Else
                        $CapsChar = ""
                    EndIf
                        
                    If GUICtrlRead($MinChar) = 1 Then
                        $MinusChar = _GUICtrlListBox_GetText($MinList, Random(0, 25, 1))
                    Else
                        $MinusChar = ""
                    EndIf
                    
                    If GUICtrlRead($ChfrChar) = 1 Then
                        $NumberChar = $De0a9[Random(0, 9, 1)]
                    Else
                        $NumberChar = ""
                    EndIf
                    
                    $PassChar = _ArrayCreate($CapsChar, $MinusChar, $NumberChar)
                    
                    Do
                        $CharToInsert = $PassChar[Random(0, 2, 1)]
                    Until $CharToInsert <> ""
                    
                    GUICtrlSetData($GenerationInput, GUICtrlRead($GenerationInput)&$CharToInsert)
                Next
            Else
                MsgBox(0, "Erreur", "Aucune conditions cochées !!!")
            EndIf
        Else
            MsgBox(0, "Erreur", "Nombre de caractères non choisit !!!")
        EndIf
    EndIf
WEnd

 
Ça peut toujours servir pour ceux en manque d'inspiration cherchant un mot de passe. :)