Jump to content

Other options (random characters)


Giggo
 Share

Recommended Posts

Hello Forum!

i found this script on the forum, you can add a box for optional characters.. Thanks.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>

Opt("GUIOnEventMode", 1)

Global $sUpper = "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 "
Global $sLower = "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 "
Global $sSymbols = "! £ $ % ^ & * ( ) _ - + = # ~ @ ; : / ? . > , < \ | ¬ ` [ ] { } "
Global $sNumbers = "0 1 2 3 4 5 6 7 8 9 "

Global $bResultSwitch = False
Global $sResult

$winMain = GUICreate("Pass Generator", 518, 327, -1, -1)
$cbxUpper = GUICtrlCreateCheckbox("Uppercase Letters", 8, 16, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$cbxLower = GUICtrlCreateCheckbox("Lowercase Letters", 8, 40, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$cbxNumbers = GUICtrlCreateCheckbox("Numbers", 8, 88, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$cbxSymbols = GUICtrlCreateCheckbox("Symbols", 8, 64, 65, 17)
$txtCount = GUICtrlCreateInput("10", 56, 110, 41, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlCreateLabel("Length:", 8, 112, 40, 17)
$btnGo = GUICtrlCreateButton("Generate", 8, 288, 75, 25)
$txtResult = GUICtrlCreateEdit("", 128, 8, 377, 129)
GUICtrlSetData(-1, "sResult")
$btnCopy = GUICtrlCreateButton("Copy to Clipboard", 152, 288, 99, 25)
$Edit1 = GUICtrlCreateEdit("", 128, 152, 377, 97)
GUICtrlSetData(-1, "°ç§*é")
$cbxOthers = GUICtrlCreateCheckbox("Others", 8, 152, 97, 17)
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $winMain)
GUICtrlSetOnEvent($btnGo, "_Generate")
GUICtrlSetOnEvent($btnCopy, "_Copy")

While 1

WEnd

Func _Generate()
    Local $sLib
    Local $iCount = GUICtrlRead($txtCount)
    $sResult = ""
    If $iCount < 0 Or Not StringIsInt($iCount) Then Return 0
    
    If GUICtrlRead($cbxOthers) = $GUI_CHECKED Then $sLib &= $Edit1  
    If GUICtrlRead($cbxLower) = $GUI_CHECKED Then $sLib &= $sLower
    If GUICtrlRead($cbxUpper) = $GUI_CHECKED Then $sLib &= $sUpper
    If GUICtrlRead($cbxNumbers) = $GUI_CHECKED Then $sLib &= $sNumbers
    If GUICtrlRead($cbxSymbols) = $GUI_CHECKED Then $sLib &= $sSymbols
    If $sLib = "" Then Return 0
    StringStripWS($sLib, 3)
    Local $aLib = StringSplit($sLib, " ")
    For $I = 1 To $iCount
        $sResult &= $aLib[Random(1, $aLib[0])]
    Next
    GUICtrlSetData($txtResult, $sResult)

EndFunc

Func _Copy()
    Local $sText = GUICtrlRead($txtResult)
    If $sText <> "" Then
        ClipPut($sText)
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

I made some attempts but... 😏

Link to comment
Share on other sites

Because of the StringSplit on space, you need to add spaces between each optional (others) characters...

OR remove all spaces everywhere and StringSplit on ""

Edited by Nine
Link to comment
Share on other sites

52 minutes ago, Nine said:

Because of the StringSplit on space, you need to add spaces between each optional (others) characters...

OR remove all spaces everywhere and StringSplit on ""

1)
Global $sUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Global $sLower = "abcdefghijklmnopqrstuvwxyz"
Global $sSymbols = "!""#$%&'()*+,-./:;<=>?@{|}~[\]^_`"
Global $sNumbers = "0123456789"
2)
Local $aLib = StringSplit($sLib, "")

NOT WORKING

 

Link to comment
Share on other sites

Of course it is working.  You must be doing something wrong.  Have you added some verification and error handling ?

#include <Array.au3>

$test = "1234567890"
$a = StringSplit($test, "")
_ArrayDisplay($a) ; working just fine

 

Link to comment
Share on other sites

9 minutes ago, Nine said:

Of course it is working.  You must be doing something wrong.  Have you added some verification and error handling ?

#include <Array.au3>

$test = "1234567890"
$a = StringSplit($test, "")
_ArrayDisplay($a) ; working just fine

 

sure that your example works, you are one of the best in the world with Autoit, but maybe the problem must be verified on editbox and not on the display I think, however I will do other tests before going craz 

Link to comment
Share on other sites

1 hour ago, Giggo said:

before going craz 

Do not go craz, nothing good will come out of that.  Take your time, find what is going wrong with your script.  Obviously I could debug it in a few mins, but what good will it give you ?  Finding a solution on your own will bring you much more satisfaction and will help you solve your programming issues in the future.  If you are facing a wall, show me you have made an effort in solving your problem, and then I will further help you out.

Link to comment
Share on other sites

19 hours ago, Nine said:

Do not go craz, nothing good will come out of that.  Take your time, find what is going wrong with your script.  Obviously I could debug it in a few mins, but what good will it give you ?  Finding a solution on your own will bring you much more satisfaction and will help you solve your programming issues in the future.  If you are facing a wall, show me you have made an effort in solving your problem, and then I will further help you out.

#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

#Region ### START Koda GUI section ###
Global $sUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

$hGui = GUICreate("TestScript", 381, 140, -1, -1)
$txtOthers = GUICtrlCreateEdit("§§§§§§§§§", 64, 8, 244, 21, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
$txtPassword = GUICtrlCreateEdit("", 8, 40, 300, 21, BitOR($ES_CENTER,$ES_AUTOVSCROLL,$ES_WANTRETURN))
$BtnGen = GUICtrlCreateButton("Generate", 8, 96, 100, 30)
$BtnExit = GUICtrlCreateButton("EXIT", 120, 96, 100, 30)
$BtnReset = GUICtrlCreateButton("Reset", 232, 96, 100, 30)
$Combo1 = GUICtrlCreateCombo("", 312, 40, 46, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))
GUICtrlSetData(-1, "6|7|8|9|10|11|11|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30", "20")
$cbxUpper = GUICtrlCreateCheckbox("Upper", 8, 72, 113, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Checkbox1 = GUICtrlCreateCheckbox("Others", 8, 8, 49, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
 $msg = GUIGetMsg()
 Select
  Case $msg = $BtnGen
   _Generate()
  Case $msg = $BtnReset 
   GUICtrlSetData($txtOthers, "")
   GUICtrlSetData($txtPassword, "")
  Case $msg = $GUI_EVENT_CLOSE Or $msg = $BtnExit
   GUIDelete()
   Exit
 EndSelect
WEnd

Func _Generate()

    Local $sLib
    Local $iCount = GUICtrlRead($Combo1)
    $sResult = ""
    If $iCount < 0 Or Not StringIsInt($iCount) Then Return 0
    
    If GUICtrlRead($cbxUpper) = $GUI_CHECKED Then $sLib &= $sUpper
    
    If $sLib = "" Then Return 0
    StringStripWS($sLib, 0)
    Local $aLib = StringSplit($sLib, "")
    For $I = 1 To $iCount
        $sResult &= $aLib[Random(1, $aLib[0])]
    Next

$test = GUICtrlRead($txtOthers)
GUICtrlSetData($txtPassword, $sResult & $test)
EndFunc

Thanks for help Nine

another example, just putting the characters at the end instead of randomizing them 

me solution is:

If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $sLib &= GUICtrlRead($txtOthers) 

 

Edited by Giggo
Link to comment
Share on other sites

Here how your _Generate function should look like :

Func _Generate()
  Local $sLib, $sResult, $aLib
  Local $iCount = GUICtrlRead($Combo1)
  If $iCount < 0 Or Not StringIsInt($iCount) Then Return

  If GUICtrlRead($cbxUpper) = $GUI_CHECKED Then $sLib &= $sUpper
  If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $sLib &= GUICtrlRead($txtOthers)

  If $sLib = "" Then Return
  $aLib = StringSplit($sLib, "")
  For $i = 1 To $iCount
    $sResult &= $aLib[Random(1, $aLib[0], 1)]
  Next
  GUICtrlSetData($txtPassword, $sResult)
EndFunc   ;==>_Generate

 

Link to comment
Share on other sites

yes! it looks cleaner, but I got there at the end 😅 nine, thanks for your time

I would like to add a label for each character with a nato alphabetic type meaning;  a = Alpha  b = Bravo etc.

Edited by Giggo
Link to comment
Share on other sites

4 hours ago, Giggo said:

yes! it looks cleaner, but I got there at the end 😅 nine, thanks for your time

I would like to add a label for each character with a nato alphabetic type meaning;  a = Alpha  b = Bravo etc.

Working Fine.... thanks NINE

;=> code revised, the original script is on the Autoit forum
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>


; characters
Global $sLower = "abcdefghijklmnopqrstuvwxyz"
Global $sUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Global $sNumbers = "0123456789"
Global $sSpecial = "!#$%&'()*+,-./" & chr(34)
Global $sSpecial2 = ":;<=>?@" 
Global $sSpecial3 = "[\^_`" 
Global $sSpecial4 = "|}~{" 
Global $sSpace = chr(32)
Global $sUnicode = "¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"

$hGui = GUICreate("Pass Generator", 392, 456, -1, -1)
GUISetBkColor(0xFFFFFF)
GUICtrlSetFont(-1, 10, 400, 0, "Courier")
$txtOthers = GUICtrlCreateInput("¡¢£¤¥¦§¨©ª«¬­®", 64, 8, 244, 21)
GUICtrlSetFont(-1, 12, 400, 0, "Courier")
$txtPassword = GUICtrlCreateInput("", 8, 40, 300, 23, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_READONLY))
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0x00008B)
GUICtrlSetFont(-1, 12, 400, 0, "Courier")
$BtnGen = GUICtrlCreateButton("Generate", 8, 160, 100, 30)
$BtnExit = GUICtrlCreateButton("EXIT", 118, 160, 100, 30)
$BtnReset = GUICtrlCreateButton("Reset", 228, 160, 100, 30)
$Combo1 = GUICtrlCreateCombo("", 312, 40, 46, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))
GUICtrlSetData(-1, "6|7|8|9|10|11|11|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30", "20")
$cbxOther = GUICtrlCreateCheckbox("Others", 8, 8, 49, 17)
$cbxLower = GUICtrlCreateCheckbox("Lower", 16, 80, 50, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$cbxUpper = GUICtrlCreateCheckbox("Upper", 16, 96, 80, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$cbxNumber = GUICtrlCreateCheckbox("Number", 16, 112, 80, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$cbxSpecial = GUICtrlCreateCheckbox("Special", 104, 80, 80, 17)
$cbxSpecial2 = GUICtrlCreateCheckbox("Special 2", 104, 96, 80, 17)
$cbxSpecial3 = GUICtrlCreateCheckbox("Special 3", 104, 112, 80, 17)
$cbxSpecial4 = GUICtrlCreateCheckbox("Special 4", 192, 80, 80, 17)
$cbxSpace = GUICtrlCreateCheckbox("Space", 192, 96, 96, 17)
$cbxUnicode = GUICtrlCreateCheckbox("Unicode", 192, 112, 80, 17)
$EditMultiPassword = GUICtrlCreateEdit("", 0, 200, 393, 257)
GUICtrlSetFont(-1, 10, 400, 0, "Courier")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
$BtnCopy = GUICtrlCreateButton("Copy", 312, 96, 46, 30)
$Group1 = GUICtrlCreateGroup("", 8, 64, 300, 89)

GUISetState(@SW_SHOW)


While 1
 $msg = GUIGetMsg()
 Select
  Case $msg = $BtnGen
   _GenNumb()
    
  Case $msg = $BtnReset 
    Reset()
  Case $msg = $BtnCopy
  ; message primary password exists yes/no
  If GUICtrlRead($txtPassword) == "" Then
  MsgBox (8240,  "Hei Bro!" ,"I can't find any passwords to copy!") 
  else
  $rc = GUICtrlRead($txtPassword)
   ClipPut($rc)
   MsgBox (8256,  "Hei Bro!" ,"Password copied!") 
   EndIf
  Case $msg = $GUI_EVENT_CLOSE Or $msg = $BtnExit
   GUIDelete()
   Exit
 EndSelect
WEnd

Func _GenNumb()
  Local $sLib, $sResult, $aLib
  ; Selection of the length of the pass
  Local $iCount = GUICtrlRead($Combo1)
  If $iCount < 0 Or Not StringIsInt($iCount) Then Return
  ; add characters
  If GUICtrlRead($cbxLower) = $GUI_CHECKED Then $sLib &= $sLower
  If GUICtrlRead($cbxUpper) = $GUI_CHECKED Then $sLib &= $sUpper
  If GUICtrlRead($cbxNumber) = $GUI_CHECKED Then $sLib &= $sNumbers
  If GUICtrlRead($cbxSpecial) = $GUI_CHECKED Then $sLib &= $sSpecial
  If GUICtrlRead($cbxSpecial2) = $GUI_CHECKED Then $sLib &= $sSpecial2
  If GUICtrlRead($cbxSpecial3) = $GUI_CHECKED Then $sLib &= $sSpecial3
  If GUICtrlRead($cbxSpecial4) = $GUI_CHECKED Then $sLib &= $sSpecial4
  If GUICtrlRead($cbxSpace) = $GUI_CHECKED Then $sLib &= $sSpace
  If GUICtrlRead($cbxUnicode) = $GUI_CHECKED Then $sLib &= $sUnicode
  ;if cbxOther is checked it adds characters from txtOthers
  If GUICtrlRead($cbxOther) = $GUI_CHECKED Then $sLib &= GUICtrlRead($txtOthers)
  ; Cycle thanks -> Nine (Autoit Team)
  If $sLib = "" Then Return
  $aLib = StringSplit($sLib, "")
  For $i = 1 To $iCount
    $sResult &= $aLib[Random(1, $aLib[0], 1)]
  Next
  ; Show display results
  GUICtrlSetData($txtPassword, $sResult)

  GUICtrlSetData($EditMultiPassword, $sResult & @CRLF, "|")
EndFunc   ;==>_GenNumb

Func Reset()
   ;go back to the starting settings
   GUICtrlSetData($txtOthers, "¡¢£¤¥¦§¨©ª«¬­®")
   GUICtrlSetData($txtPassword, "")
   GUICtrlSetData($EditMultiPassword, "")
   GUICtrlSetState($cbxOther, $GUI_UNCHECKED)
   GUICtrlSetState($cbxSpace, $GUI_UNCHECKED)
   GUICtrlSetState($cbxSpecial, $GUI_UNCHECKED)
   GUICtrlSetState($cbxSpecial2, $GUI_UNCHECKED)
   GUICtrlSetState($cbxSpecial3, $GUI_UNCHECKED)
   GUICtrlSetState($cbxSpecial4, $GUI_UNCHECKED)
   GUICtrlSetState($cbxUnicode, $GUI_UNCHECKED)
EndFunc   ;==>Reset

 

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...