Vladi243 Posted July 11, 2008 Posted July 11, 2008 Hey, I try to create an application that generates a random password. I try to make that I can choose which kind of notes to use. I succeed to make this till now: expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $RandomPassword = GUICreate("Random Password", 240, 174, 379, 334) $DigitsCheckbox = GUICtrlCreateCheckbox("Digits", 16, 16, 97, 17) $SpecialNotesCheckbox = GUICtrlCreateCheckbox("Special Notes", 16, 48, 97, 17) $LettersCheckbox = GUICtrlCreateCheckbox("Letters", 136, 16, 97, 17) $CapitalLettersCheckbox = GUICtrlCreateCheckbox("Capital Letters", 136, 48, 97, 17) $Password = GUICtrlCreateLabel("Password:", 16, 112, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, "David") $Generate = GUICtrlCreateButton("Generate", 16, 142, 70, 20, 0) $Copy = GUICtrlCreateButton("Copy", 130, 142, 70, 20, 0) $PasswordNotesCount = GUICtrlCreateInput("5", 85, 80, 40, 21, $ES_NUMBER) GUICtrlSetLimit ($PasswordNotesCount, 2, 1) $ChooseNotesCountLabel = GUICtrlCreateLabel("Notes count:", 16, 82, 65, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Generate GenerateRandomPassword() EndSwitch WEnd Func GenerateRandomPassword() $Letters = "q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m" $CapitalLetters = "Q,W,E,R,T,Y,U,I,O,P,A,S,D,F,G,H,J,K,L,Z,X,C,V,B,N,M" $Digits = "1,2,3,4,5,6,7,8,9,0" $SpecialNotes = "¥,₪,£,¢,¡,~,¦,§,¨,?,«,¬,°,µ,¶" $LettersCheckboxRead = GUICtrlRead ($LettersCheckbox) If $LettersCheckboxRead = 1 Then $Array=StringSplit($Letters,",") $1=Random (1, UBound ($Array)-1, 1) $2=Random (1, UBound ($Array)-1, 1) $3=Random (1, UBound ($Array)-1, 1) $4=Random (1, UBound ($Array)-1, 1) $5=Random (1, UBound ($Array)-1, 1) $6=Random (1, UBound ($Array)-1, 1) $7=Random (1, UBound ($Array)-1, 1) $8=Random (1, UBound ($Array)-1, 1) $9=Random (1, UBound ($Array)-1, 1) $10=Random (1, UBound ($Array)-1, 1) $GenerateRead = GUICtrlRead ($PasswordNotesCount) If $GenerateRead= 1 Then GUICtrlSetData ($Password, "Password: " & $Array[$1]) If $GenerateRead= 2 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2]) If $GenerateRead= 3 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2] & $Array[$3]) If $GenerateRead= 4 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2] & $Array[$3] & $Array[$4]) If $GenerateRead= 5 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2] & $Array[$3] & $Array[$4] & $Array[$5]) If $GenerateRead= 6 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2] & $Array[$3] & $Array[$4] & $Array[$5] & $Array[$6]) If $GenerateRead= 7 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2] & $Array[$3] & $Array[$4] & $Array[$5] & $Array[$6] & $Array[$7]) If $GenerateRead= 8 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2] & $Array[$3] & $Array[$4] & $Array[$5] & $Array[$6] & $Array[$7] & $Array[$8]) If $GenerateRead= 9 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2] & $Array[$3] & $Array[$4] & $Array[$5] & $Array[$6] & $Array[$7] & $Array[$8] & $Array[$9]) If $GenerateRead= 10 Then GUICtrlSetData ($Password, "Password: " & $Array[$1] & $Array[$2] & $Array[$3] & $Array[$4] & $Array[$5] & $Array[$6] & $Array[$7] & $Array[$8] & $Array[$9] & $Array[$10]) EndIf EndFunc It works only with Letters and you can choose maximum 10 notes to generate. Do you have suggestions, how to combine Capital Letters, Digits and Special Notes with the script? My script is a little big. Do you have any suggestion to make it short?
Xenobiologist Posted July 11, 2008 Posted July 11, 2008 ConsoleWrite(Random_Password(15) & @LF) Func Random_Password($MAXLENGTH) Local $PASSWORD = '' For $i = 1 To $MAXLENGTH $PASSWORD &= Chr(Random(33, 126)) Next Return $PASSWORD EndFunc ;==>Random_Password Hi, just put a switch in the function and set the ranges of what you need. Like 65 to 90 for capital letters. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Skruge Posted July 11, 2008 Posted July 11, 2008 expandcollapse popup#include <GUIConstants.au3> Local $iClassFlags = 0 Local $iLength = 0 #Region ### START Koda GUI section ### Form= $RandomPassword = GUICreate("Random Password", 240, 174, 379, 334) $DigitsCheckbox = GUICtrlCreateCheckbox("Digits", 16, 16, 97, 17) $SpecialNotesCheckbox = GUICtrlCreateCheckbox("Special Notes", 16, 48, 97, 17) $LettersCheckbox = GUICtrlCreateCheckbox("Letters", 136, 16, 97, 17) $CapitalLettersCheckbox = GUICtrlCreateCheckbox("Capital Letters", 136, 48, 97, 17) $Password = GUICtrlCreateLabel("Password:", 16, 112, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, "David") $Generate = GUICtrlCreateButton("Generate", 16, 142, 70, 20, 0) $Copy = GUICtrlCreateButton("Copy", 130, 142, 70, 20, 0) $PasswordNotesCount = GUICtrlCreateInput("5", 85, 80, 40, 21, $ES_NUMBER) GUICtrlSetLimit($PasswordNotesCount, 2, 1) $ChooseNotesCountLabel = GUICtrlCreateLabel("Notes count:", 16, 82, 65, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Generate $iLength = GUICtrlRead($PasswordNotesCount) $iClassFlags = 0 If BitAND(GUICtrlRead($LettersCheckbox), $GUI_CHECKED) Then $iClassFlags += 1 If BitAND(GUICtrlRead($CapitalLettersCheckbox), $GUI_CHECKED) Then $iClassFlags += 2 If BitAND(GUICtrlRead($DigitsCheckbox), $GUI_CHECKED) Then $iClassFlags += 4 If BitAND(GUICtrlRead($SpecialNotesCheckbox), $GUI_CHECKED) Then $iClassFlags += 8 GUICtrlSetData($Password, "Password: " & GenerateRandomPassword($iClassFlags, $iLength)) EndSwitch WEnd Func GenerateRandomPassword($iClasses = 1, $iLength = 8) Local $sCharSet = "" Local $sPassword = "" If BitAND($iClasses, 1) Then $sCharSet &= "qwertyuiopasdfghjklzxcvbnm" If BitAND($iClasses, 2) Then $sCharSet &= "QWERTYUIOPASDFGHJKLZXCVBNM" If BitAND($iClasses, 4) Then $sCharSet &= "1234567890" If BitAND($iClasses, 8) Then $sCharSet &= "¥?£¢¡~¦§¨?«¬°µ¶" For $iX = 1 To $iLength $sPassword &= StringMid($sCharSet, Random(1, StringLen($sCharSet), 1), 1) Next Return $sPassword EndFunc ;==>GenerateRandomPassword [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]
Vladi243 Posted July 11, 2008 Author Posted July 11, 2008 ConsoleWrite(Random_Password(15) & @LF) Func Random_Password($MAXLENGTH) Local $PASSWORD = '' For $i = 1 To $MAXLENGTH $PASSWORD &= Chr(Random(33, 126)) Next Return $PASSWORD EndFunc ;==>Random_Password Hi, just put a switch in the function and set the ranges of what you need. Like 65 to 90 for capital letters. MegaThanks, it's better way to generate random note. I still need a suggestion, how to make an option to choose which kind of notes to generate (letters/capital letters/digits)
Xenobiologist Posted July 11, 2008 Posted July 11, 2008 Hi, I told you already. Just make a switch for the options. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Vladi243 Posted July 11, 2008 Author Posted July 11, 2008 expandcollapse popup#include <GUIConstants.au3> Local $iClassFlags = 0 Local $iLength = 0 #Region ### START Koda GUI section ### Form= $RandomPassword = GUICreate("Random Password", 240, 174, 379, 334) $DigitsCheckbox = GUICtrlCreateCheckbox("Digits", 16, 16, 97, 17) $SpecialNotesCheckbox = GUICtrlCreateCheckbox("Special Notes", 16, 48, 97, 17) $LettersCheckbox = GUICtrlCreateCheckbox("Letters", 136, 16, 97, 17) $CapitalLettersCheckbox = GUICtrlCreateCheckbox("Capital Letters", 136, 48, 97, 17) $Password = GUICtrlCreateLabel("Password:", 16, 112, 350, 20) GUICtrlSetFont(-1, 12, 400, 0, "David") $Generate = GUICtrlCreateButton("Generate", 16, 142, 70, 20, 0) $Copy = GUICtrlCreateButton("Copy", 130, 142, 70, 20, 0) $PasswordNotesCount = GUICtrlCreateInput("5", 85, 80, 40, 21, $ES_NUMBER) GUICtrlSetLimit($PasswordNotesCount, 2, 1) $ChooseNotesCountLabel = GUICtrlCreateLabel("Notes count:", 16, 82, 65, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Generate $iLength = GUICtrlRead($PasswordNotesCount) $iClassFlags = 0 If BitAND(GUICtrlRead($LettersCheckbox), $GUI_CHECKED) Then $iClassFlags += 1 If BitAND(GUICtrlRead($CapitalLettersCheckbox), $GUI_CHECKED) Then $iClassFlags += 2 If BitAND(GUICtrlRead($DigitsCheckbox), $GUI_CHECKED) Then $iClassFlags += 4 If BitAND(GUICtrlRead($SpecialNotesCheckbox), $GUI_CHECKED) Then $iClassFlags += 8 GUICtrlSetData($Password, "Password: " & GenerateRandomPassword($iClassFlags, $iLength)) EndSwitch WEnd Func GenerateRandomPassword($iClasses = 1, $iLength = 8) Local $sCharSet = "" Local $sPassword = "" If BitAND($iClasses, 1) Then $sCharSet &= "qwertyuiopasdfghjklzxcvbnm" If BitAND($iClasses, 2) Then $sCharSet &= "QWERTYUIOPASDFGHJKLZXCVBNM" If BitAND($iClasses, 4) Then $sCharSet &= "1234567890" If BitAND($iClasses, 8) Then $sCharSet &= "¥?£¢¡~¦§¨?«¬°µ¶" For $iX = 1 To $iLength $sPassword &= StringMid($sCharSet, Random(1, StringLen($sCharSet), 1), 1) Next Return $sPassword EndFunc ;==>GenerateRandomPasswordThank you very very much. You really helped me.
Vladi243 Posted July 11, 2008 Author Posted July 11, 2008 Hi,I told you already.Just make a switch for the options.MegaOK, I understand now muttley
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