Skip to content

Instantly share code, notes, and snippets.

@sharuzzaman
Created July 16, 2024 00:40
Show Gist options
  • Save sharuzzaman/231c48ee35eb1fdb4d31046fe43fe25d to your computer and use it in GitHub Desktop.
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
#!/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