Created
July 16, 2024 00:40
-
-
Save sharuzzaman/231c48ee35eb1fdb4d31046fe43fe25d to your computer and use it in GitHub Desktop.
This script will create a password with 12 alphanumeric character, split into 3 parts of 4 character each, and using dash "-" as the separator
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 | |
# | |
# This script will create a password with 12 alphanumeric character, split into 3 parts of 4 character each, and using dash "-" as | |
# the separator | |
# | |
# Example: pyYq-gFcn-jRa3 | |
# | |
generate_password () { | |
while true | |
do | |
raw_string=$(base64 /dev/urandom | head -n1 | tr -cd '[:alnum:]' | cut -c-12 | grep '[0-9]') | |
if [ ! -z "${raw_string}" ]; then | |
final_password="${raw_string:0:4}-${raw_string:4:4}-${raw_string:8:4}" | |
echo "${final_password}" | |
break | |
fi | |
done | |
} | |
generate_password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment