Last active
October 17, 2020 04:35
-
-
Save purarue/b357fc74ab1bdf5e8aa35aa5ca28099e to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# enter length on command line. e.g. genpasswd 50 | |
#B8G6I1l0OQDS5Z2 are problematic characters, could be mistaken as others characters when trying to read passwords. | |
passwordChars="abcdefghijkmnopqrstuvwxyzACEFHJKLMNPRTUVWXY()~%^&*-+=|{}[]<>,.?/3479" | |
passwdLength=$1 # get length from CLI | |
if [[ "$passwdLength" -le 0 ]]; then | |
passwdLength=30 # default length if not given | |
fi | |
# on average (1000 tests), the amount of characters that comes from /dev/urandom that fit the passwordChars | |
# is 26.1%. Reduced down by tr, 1000 characters fro had a min of 217 and a max of 310, with a standard deviation | |
# of 13.5, so multiplying by 5 would probably have been enough, 15 is just to be safe. | |
streamLength=$(( $passwdLength * 15 )) | |
generatedPasswd=$(head -c "$streamLength" /dev/urandom | LC_CTYPE=C tr -dc "$passwordChars" | head -c "$passwdLength") | |
echo -e "$generatedPasswd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replaced by https://github.com/seanbreckenridge/genpasswd and https://sean.fish/d/genpass