Last active
August 29, 2015 14:00
-
-
Save lavoiesl/11023640 to your computer and use it in GitHub Desktop.
password generator + key-store
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
#!/bin/bash | |
# Generates a random password using only non-ambiguous alphanumeric characters | |
# Usage: genpasswd.sh [length] | |
# | |
# @link https://gist.github.com/lavoiesl/11023640 | |
length=16 | |
if [[ -n "$1" ]]; then | |
length="$1" | |
fi | |
head -c $(( 2 * length)) /dev/urandom | base64 | sed -E 's/[^23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]//g' | head -c "${length}" | |
echo |
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
#!/bin/bash | |
# Generate a random string for a given key using genpasswd.sh, | |
# store it into ~/.key-random and return it. | |
# If key already exists, return it instead of regenerating a new one. | |
# | |
# @link https://gist.github.com/lavoiesl/11023640 | |
store="$HOME/.key-random" | |
if [ -z "$1" ]; then | |
echo "Usage: key-random.sh key [length]" >&2 | |
exit 1; | |
fi | |
key="$1" | |
touch "$store" | |
pass=$(grep "^$key=" "$store" | sed "s/^$key=//") | |
if [ -z "$pass" ]; then | |
length="$2" | |
pass=$(genpasswd.sh "${length}") | |
echo "${key}=${pass}" >> "${store}" | |
fi | |
echo "${pass}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment