set LengthList to {"L1", "L2", "L3", "L4", "L5", "L6", "L7", "L8", "L9", "L10", "L11", "L12", "L13", "L14", "L15", "L16", "L17", "L18", "L19", "L20"}
set NumList to {"N0", "N1", "N2", "N3", "N4", "N5", "N6", "N7", "N8", "N9"}
set SpecList to {"S0", "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9"}
set answer to choose from list LengthList & NumList & SpecList with prompt "Set Up Password Parameters:
L for Length
N for Numeric Characters
S for Special Characters" with title "Password Information Input" with multiple selections allowed
if answer is not false then
set i to count of answer
if (i = 3) then
if (((item 1 of answer) contains "L") and ((item 2 of answer) contains "N") and ((item 3 of answer) contains "S")) then
set PLength to ((characters 2 thru -1 of (item 1 of answer)) as string)
set PNum to ((characters 2 thru -1 of (item 2 of answer)) as string)
set PSpec to ((characters 2 thru -1 of (item 3 of answer)) as string)
set aLength to PLength as number
set NNum to PNum as number
set NSpec to PSpec as number
else
display dialog "You must select one of each parameter for password: Length, Numeric Characters, and Special Characters" with icon file (POSIX file "/Users/dracon/Documents/Misc Graphics/Icons/Icon Fix Mojave/Password/Password Maker.png") with title "Error!"
return
end if
else
display dialog "You must select 3 parameters." with icon file (POSIX file "/Users/dracon/Documents/Misc Graphics/Icons/Icon Fix Mojave/Password/Password Maker.png") with title "Error!"
return
end if
else
display dialog "This is really crappy input." with icon file (POSIX file "/Users/dracon/Documents/Misc Graphics/Icons/Icon Fix Mojave/Password/Password Maker.png") with title "Error!"
return
end if
set Pass to GenerateRandom(aLength, NNum, NSpec)
display dialog Pass & "
OK copies to clipboard." with icon file (POSIX file "/Users/dracon/Documents/Misc Graphics/Icons/Icon Fix Mojave/Password/Password Maker.png") with title "Your Password"
set the clipboard to Pass
on GenerateRandom(aLength, NNum, NSpec)
set ie to NNum + NSpec
if ((ie is greater than aLength) or (aLength is less than 1)) then
display dialog "Total of Special and Numerical Characters Exceeds String Length or Other Crap Problems!" with icon file (POSIX file "/Users/dracon/Documents/Misc Graphics/Icons/Icon Fix Mojave/Password/Password Maker.png") with title "Error!"
error number -128 (* user cancelled *)
end if
set ie to aLength
if (ie is greater than 20) then
display dialog "String Length Exceeds 20 Characters!" with icon file (POSIX file "/Users/dracon/Documents/Misc Graphics/Icons/Icon Fix Mojave/Password/Password Maker.png") with title "Error!"
error number -128 (* user cancelled *)
end if
set PFrame to {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
set AlphaChars to {"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", "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"}
set NumChars to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
set SpecChars to {"!", "@", "#", "$", "%", "^", "&", "*", "(", ")"}
set aString to ""
(*
===========================================================
*)
if (NNum is not equal to 0) then
set cNum to 0
set nstop to 0
repeat until (cNum is not less than NNum)
set nstop to nstop + 1
if (nstop is greater than (NNum + 10)) then exit repeat
set a to (random number from 1 to aLength)
if (item {a} of PFrame is 1) then
set item {a} of PFrame to 2
set cNum to cNum + 1
end if
end repeat
end if
(*
==============================================================
*)
if (NSpec is not equal to 0) then
set cNum to 0
set nstop to 0
repeat until (cNum is not less than NSpec)
set nstop to nstop + 1
if (nstop is greater than (NSpec + 10)) then exit repeat
set a to (random number from 1 to aLength)
if (item {a} of PFrame is 1) then
set item {a} of PFrame to 3
set cNum to cNum + 1
end if
end repeat
end if
(*
==================================================================
*)
set a to 1
repeat aLength times
if (item {a} of PFrame = 2) then
set b to (random number from 1 to 10)
set aString to aString & item {b} of NumChars
else
if (item {a} of PFrame = 3) then
set b to (random number from 1 to 10)
set aString to aString & item {b} of SpecChars
else
set b to (random number from 1 to 52)
set aString to aString & item {b} of AlphaChars
end if
end if
set a to a + 1
end repeat
(*
==============================================================
*)
return aString
end GenerateRandom