Thursday, July 25, 2013

My RPG

I created a simple random password generator from AutoHotKey. This code produces a nine character password with 3 sets of non-repeating characters. Set one is lower case letters, set two has upper case letters and set three has numbers. Each set is then randomly ordered.

I've hotkeyed this script to launch on pressing the scroll lock in my master AutoHotKey script and it places the password into the clipboard and creates a message box, in case I need to write out the password on a piece of paper.


clipboard = 
Length = 3
Characters = abcdefghijklmnopqrstuvwxyz

Loop 1
 {
  Passwords .= "`r`n"
  UsedRandomNumbers =
  Loop %Length%
   {
    GetNewRandomNumber:
    Random, RandomNumber, 1, % StrLen(Characters)
    if RandomNumber in %UsedRandomNumbers%
     goto GetNewRandomNumber
    UsedRandomNumbers := ((UsedRandomNumbers)(RandomNumber)",") 
    Psswords .= SubStr(Characters, RandomNumber, 1)
   }
 }

ULength = 3
UCharacters = ABCDEFGHIJKLMNOPQRSTUVWXYZ

Loop 1
 {
  Passwords .= "`r`n"
  UUsedRandomNumbers =
  Loop %ULength%
   {
    UGetNewRandomNumber:
    Random, URandomNumber, 1, % StrLen(UCharacters)
    if URandomNumber in %UUsedRandomNumbers%
     goto UGetNewRandomNumber
    UUsedRandomNumbers := ((UUsedRandomNumbers)(URandomNumber)",") 
    UPsswords .= SubStr(UCharacters, URandomNumber, 1)
   }
 }

NLength = 3
NCharacters = 1234567890

Loop 1
 {
  Passwords .= "`r`n"
  NUsedRandomNumbers =
  Loop %NLength%
   {
    NGetNewRandomNumber:
    Random, NRandomNumber, 1, % StrLen(NCharacters)
    if NRandomNumber in %NUsedRandomNumbers%
     goto NGetNewRandomNumber
    NUsedRandomNumbers := ((NUsedRandomNumbers)(NRandomNumber)",") 
    NPsswords .= SubStr(NCharacters, NRandomNumber, 1)
   }
 }
random, rand, 1, 3
IfEqual, rand, 1, Goto, a1
IfEqual, rand, 2, Goto, a2
IfEqual, rand, 3, Goto, a3
return
a1:
clipboard = %Psswords%%UPsswords%%NPsswords%
Msgbox,, Random Password Generator, %Psswords%%UPsswords%%NPsswords% saved to clipboard!
ExitApp
return
a2:
clipboard = %UPsswords%%NPsswords%%Psswords%
Msgbox,, Random Password Generator, %UPsswords%%NPsswords%%Psswords% saved to clipboard!
ExitApp
return
a3:
clipboard = %NPsswords%%Psswords%%UPsswords%
Msgbox,, Random Password Generator, %NPsswords%%Psswords%%UPsswords% saved to clipboard!
ExitApp
Post a Comment