How to create a password generator?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
whats_up
Posts: 89
Joined: 29 Apr 2018, 05:09

How to create a password generator?

24 Apr 2021, 19:52

Random can choose random numbers.

But what about random letters or any other symbols?

Does it mean, that I need to create an array, and put there all the "a, A, b, B, c, C, ..." (and other symbols) and then make a loop with a Random, as much times, as I want my potential new password's length gonna be?

Do you know the most effective way to build a code for that?

Thanks 8-)
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: How to create a password generator?

24 Apr 2021, 20:18

Code: Select all

MsgBox, 64, Your new password, % newPass(8)

newPass(length) {
 Loop, %length% {
  Random, rand, 33, 126
  pass .= Chr(rand)
 }
 Return pass
}
User avatar
whats_up
Posts: 89
Joined: 29 Apr 2018, 05:09

Re: How to create a password generator?

24 Apr 2021, 20:33

mikeyww wrote:
24 Apr 2021, 20:18
Spoiler
Thanks for that.

And how about passwords made from just lowercase, UPPERCASE and numbers?

48-57 (the digits 0-9)
65-90 (uppercase A-Z)
97-122 (lowercase a-z)

How to make Random choose symbols from those three ranges?

--------

And can you say what 64 means right after MsgBox ?
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: How to create a password generator?

24 Apr 2021, 20:51

You answered your own question. Change the ASCII range for Random. Use any sequence needed.

64 = "info icon"

Explained: MsgBox
User avatar
whats_up
Posts: 89
Joined: 29 Apr 2018, 05:09

Re: How to create a password generator?

24 Apr 2021, 20:53

mikeyww wrote:
24 Apr 2021, 20:51
You answered your own question. Change the ASCII range for Random. Use any sequence needed.

64 = "info icon"

Explained: MsgBox
Bot I'm not gonna use MsgBox for my purposes.
I want simply to SendInput those passwords.
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: How to create a password generator?

24 Apr 2021, 20:59

That's wonderful. I provided the information for you because I was answering your question.
User avatar
whats_up
Posts: 89
Joined: 29 Apr 2018, 05:09

Re: How to create a password generator?

24 Apr 2021, 22:12

mikeyww wrote:
24 Apr 2021, 20:59
That's wonderful. I provided the information for you because I was answering your question.
I don't get it ...

Here is the main question:
And how about passwords made from just lowercase, UPPERCASE and numbers?

48-57 (the digits 0-9)
65-90 (uppercase A-Z)
97-122 (lowercase a-z)

How to make Random choose symbols from those three ranges?
I need to use those ranges for making a password and putting it not via MsgBox, but via SendInput.
User avatar
Chunjee
Posts: 1467
Joined: 18 Apr 2014, 19:05
Contact:

Re: How to create a password generator?

24 Apr 2021, 22:37

how long are these passwords going to be? Personally I go for ten characters or more.
User avatar
whats_up
Posts: 89
Joined: 29 Apr 2018, 05:09

Re: How to create a password generator?

24 Apr 2021, 22:42

Chunjee wrote:
24 Apr 2021, 22:37
how long are these passwords going to be? Personally I go for ten characters or more.
I would also implement some options for those: when there would be a need of 8 symbols, I would press a needed combination + digit 8, when I would need 15 symbols, would press needed combination + 15, etc ...
User avatar
whats_up
Posts: 89
Joined: 29 Apr 2018, 05:09

Re: How to create a password generator?

24 Apr 2021, 23:54

mikeyww wrote:
24 Apr 2021, 20:59
That's wonderful. I provided the information for you because I was answering your question.
Should it be one main Random ... which will choose between three other Randoms?

Or can you suggest a better solution for that?
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: How to create a password generator?

25 Apr 2021, 05:43

Here is how you can specify each type, and get random arrangements.

Code: Select all

F3::Send % newPass(2, 5, 3) "`n"

newPass(lower, upper := 0, digits := 0) {
 Static set := [[97, 122], [65, 90], [48, 57]]
 str := []
 For type, qty in [lower, upper, digits]  ; Loop through the three types of characters
  Loop, %qty% {                           ; Generate number of characters of this type
   Random, rand, set[type].1, set[type].2 ; Set boundaries for random numbers
   str.Push(Chr(rand))                    ; Push the character onto the stack
  }
 Loop, % str.Count() {                    ; Loop according to the stack size
  Random, rand, 1, str.Count()            ; Pick a random position within the remaining characters
  pass .= str.RemoveAt(rand)              ; Remove character; append to the password
 }
 Return pass
}
User avatar
Maestr0
Posts: 136
Joined: 05 Dec 2013, 17:43

Re: How to create a password generator?

06 Oct 2021, 13:57

mikeyww wrote:
25 Apr 2021, 05:43
Here is how you can specify each type, and get random arrangements.

Code: Select all

F3::Send % newPass(2, 5, 3) "`n"

newPass(lower, upper := 0, digits := 0) {
 Static set := [[97, 122], [65, 90], [48, 57]]
 str := []
 For type, qty in [lower, upper, digits]  ; Loop through the three types of characters
  Loop, %qty% {                           ; Generate number of characters of this type
   Random, rand, set[type].1, set[type].2 ; Set boundaries for random numbers
   str.Push(Chr(rand))                    ; Push the character onto the stack
  }
 Loop, % str.Count() {                    ; Loop according to the stack size
  Random, rand, 1, str.Count()            ; Pick a random position within the remaining characters
  pass .= str.RemoveAt(rand)              ; Remove character; append to the password
 }
 Return pass
}
awesome!
fiendhunter
Posts: 140
Joined: 24 Jul 2019, 15:27

Re: How to create a password generator?

07 Oct 2021, 05:15

Code: Select all

F3::
Length = 17                                                                                   ; length of the password
Characters = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$^&*()         ; included characters

Loop, 10                                                                                      ; how many password ganerate
 {
  Passwords .= "`r`n"
  UsedRandomNumbers =
  Loop %Length%
   {
    GetNewRandomNumber:
    Random, RandomNumber, 1, % StrLen(Characters)
    if RandomNumber in %UsedRandomNumbers%
     goto GetNewRandomNumber
    UsedRandomNumbers := ((UsedRandomNumbers)(RandomNumber)",") 
    Passwords .= SubStr(Characters, RandomNumber, 1)
   }
 }
FileDelete, %A_Temp%\Passwords.txt
FileAppend, % SubStr(Passwords, 3), %A_Temp%\Passwords.txt
Run, notepad.exe "%A_Temp%\Passwords.txt"
User avatar
Chunjee
Posts: 1467
Joined: 18 Apr 2014, 19:05
Contact:

Re: How to create a password generator?

11 Oct 2022, 13:37

whats_up wrote:
24 Apr 2021, 19:52
Does it mean, that I need to create an array, and put there all the "a, A, b, B, c, C, ..." (and other symbols) and then make a loop with a Random, as much times, as I want my potential new password's length gonna be?
seems reasonable

Code: Select all

A := new biga() ; requires https://github.com/biga-ahk/biga.ahk

allCharOptions := "abcdefghijklmnopqrstuvwxyzAbCDEFGHIJKLMONPQRSTUVWXYZ0123456789"

F1::
sendInput, % fn_generatPassword(allCharOptions, 16)
; => "8g8YUWTRaltMwNWe"
return

fn_generatPassword(param_map, param_length:=8)
{
    ; turn string argument into an array
    chars := strSplit(param_map)
    ; loop as many times as needed to achieve the password length
    loop, % param_length {
        ; append a random element to the password string
        password .= biga.sample(chars)
    }
    return password
}
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: How to create a password generator?

12 Oct 2022, 02:01

I wrote a Password Generator: viewtopic.php?f=83&t=95321
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Spawnova and 131 guests