Created
May 24, 2020 10:17
-
-
Save surajsau/99771dd38cbfde33d294a176e3601a7f to your computer and use it in GitHub Desktop.
Applescript for Password Generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on generatePassword() | |
set chars to {} | |
set shuffledChars to {} | |
-- (1) | |
repeat with index from 1 to 15 | |
if index is less than 5 then | |
set chars to chars & some item of lowercase | |
else if index is less than 10 then | |
set chars to chars & some item of uppercase | |
else if index is less than 13 then | |
set chars to chars & some item of numericals | |
else | |
set chars to chars & some item of symbols | |
end if | |
end repeat | |
-- (2) | |
repeat 15 times | |
-- (3) | |
set randomIndex to random number from 1 to (count chars) | |
set randomChar to item randomIndex of chars | |
-- (4) | |
set shuffledChars to shuffledChars & randomChar | |
-- (5) | |
set reducedChars to {} | |
repeat with index from 1 to (count chars) | |
if index is not equal to randomIndex then | |
set reducedChars to reducedChars & item index of chars | |
end if | |
end repeat | |
set chars to reducedChars | |
end repeat | |
-- (6) | |
return shuffledChars as text | |
end generatePassword |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment