diff options
| author | Scott Moser <smoser@brickies.net> | 2016-11-03 13:40:17 (GMT) |
|---|---|---|
| committer | Scott Moser <smoser@brickies.net> | 2016-11-03 13:40:17 (GMT) |
| commit | 9a7c371ef329cf78f256d0a5a8f475d9c57f5477 (patch) | |
| tree | a5457d8e39a8357c3fb57bd406e5d2b953fbf5ea | |
| parent | 371293d8e747f123f5782e27a0b80db0c4050b70 (diff) | |
set default password to 'gocubsgo'
The smiley face was hard or impossible to type in some scenarios.
The new password still pays homage to the Cubs.
Thanks to all those who typed 'cubswin:)' and helped to bring the
Cubs a World Series victory in 2016.
| -rw-r--r-- | bin/encrypt-pass | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/encrypt-pass b/bin/encrypt-pass new file mode 100644 index 0000000..07bd746 --- /dev/null +++ b/bin/encrypt-pass @@ -0,0 +1,50 @@ +#!/bin/sh +# vi: ts=4 noexpandtab +Usage() { + cat <<EOF +Usage: ${0##*/} password [format] + +convert password to crypt'd password suitable for /etc/shadow + + format is one of: + md5 [default] + sha256 + sha512 +EOF +} + +encrypt_pass() { + local pass="$1" fmt="${2:-md5}" fmt_arg="" + case "$fmt" in + md5) fmt_arg='$1$';; + sha256) fmt_arg='$5$';; + sha512) fmt_arg='$6$';; + \$*\$) fmt_arg="$fmt";; + esac + enc=$(echo "$pass" | + perl -e ' + $p=<STDIN>; chomp($p); + $salt = join "", map { (q(a)..q(z))[rand(26)] } 1 .. 8; + if (${ARGV[0]}) { $salt = "${ARGV[0]}$salt\$"; } + print crypt($p, "$salt") . "\n";' "$fmt_arg") || return + [ -n "${enc}" ] && [ "${enc#${fmt_arg}}" != "${enc}" ] && + _RET="$enc" +} +error() { echo "$@" 1>&2; } +fail() { [ $# -eq 0 ] || error "$@"; exit 1; } + +[ "$1" = "--help" -o "$1" = "-h" ] && { Usage; exit 0; } +if ! [ $# -eq 1 -o $# -eq 2 ]; then + Usage 1>&2 + error "got $# args, expected 1 or 2" + exit 1 +fi + +password="$1" +fmt=${2:-md5} +if [ "$1" = "-" ]; then + read password || fail "failed to read password from stdin" +fi + +encrypt_pass "$password" "$fmt" || fail "failed to encrypt password in '$fmt'" +echo "$_RET" |
