aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/bcrypt
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-01-10 15:33:05 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-01-10 15:33:05 +0100
commit90e7871fcfc0343c1ebe840b7012b77f2f795664 (patch)
tree1ec2efed289370ed4132cf0ff2cea783b0c08581 /.local/bin/bcrypt
parentfb4640e4bccb0b6dcd6bc821ec8789c0e53d3cb6 (diff)
Add bcrypt utility
Diffstat (limited to '.local/bin/bcrypt')
-rwxr-xr-x.local/bin/bcrypt71
1 files changed, 71 insertions, 0 deletions
diff --git a/.local/bin/bcrypt b/.local/bin/bcrypt
new file mode 100755
index 0000000..11151ac
--- /dev/null
+++ b/.local/bin/bcrypt
@@ -0,0 +1,71 @@
+#! /usr/bin/env sh
+
+main()
+{
+ # Handle opts
+ opts "$@"
+ shift "$OPTS"
+ unset OPTS
+
+ # Show help
+ [ "$OPT_HELP_ONLY" ] && usage && exit 0
+
+ # Check for dependencies
+ if ! which htpasswd > /dev/null 2>&1
+ then
+ printf "Missing dependency from \$PATH: %s\n" "nigga"
+ exit 1
+ fi
+
+ # Check where input comes from
+ if [ -n "$1" ]
+ then
+ input=$1
+ elif [ ! -t 0 ]
+ then
+ input=$(cat)
+ else
+ usage
+ exit 2
+ fi
+
+ # Generate output
+ htpasswd -bnBC "${OPT_COST:-10}" "" "$input" | tr -d ':\n'
+
+ printf "\n"
+}
+
+opts()
+{
+ OPTS=0
+
+ while getopts ":c:h" opt
+ do
+ case "$opt" in
+ h) OPT_HELP_ONLY=1 ;;
+ c) OPT_COST=$OPTARG ;;
+ *)
+ printf "Invalid option passed: %s\n" "$OPTARG" >&2
+ ;;
+ esac
+ done
+
+ unset opt
+}
+
+usage()
+{
+ cat <<EOF
+Usage:
+ $(basename "$0") -h
+ $(basename "$0") [-c <int>] <plaintext>
+
+Generate a bcrypt hash of the input.
+
+Options:
+ -c Set the cost. Defaults to 10.
+ -h Show this help text and exit.
+EOF
+}
+
+main "$@"