Last active
April 28, 2024 03:45
-
-
Save darkn3rd/746a7c8c0752f344c9d196594599ec6b to your computer and use it in GitHub Desktop.
randpasswd bash function
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
randpasswd() { | |
NUM=${1:-32} | |
# macOS scenario | |
if [[ $(uname -s) == "Darwin" ]]; then | |
perl -pe 'binmode(STDIN, ":bytes"); tr/A-Za-z0-9//dc;' < /dev/urandom | head -c $NUM | |
else | |
# tested with: GNU/Linux, Cygwin, MSys | |
tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w $NUM | sed 1q | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment