Last active
August 29, 2015 14:02
-
-
Save michaelsbradleyjr/dec5d69af50832166274 to your computer and use it in GitHub Desktop.
password and hash generation with apg, htpasswd/bcrypt
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 | |
# password and hash pair generation with apg, htpasswd/bcrypt | |
# example usage: | |
# source this file or include the passnhash function in your .bash_profile/.bashrc | |
# then: `passnhash 0 35 14` | |
# prerequisites: | |
# 1) recent version of htpasswd that supports bcrypt (-B flag) | |
# deb: `apt-get install apache2-utils` | |
# mac: `brew install homebrew/apache/httpd24` | |
# 2) apg | |
# deb: `apt-get install apg` | |
# mac: `brew install apg` | |
# be thoughtful if/when outputting to the terminal instead of a file | |
function passnhash () { | |
local ALGO=$1 | |
local LENG=$2 | |
local COST=$3 | |
local PASS=$(apg -a "$ALGO" -m "$LENG" -n 1) | |
# "username" is a placeholder value since we're only interested in the hash | |
local HASH=$(echo "$PASS" | htpasswd -n -i -B -C "$COST" username | tr -d '\n' | awk -F: '{ print $2 }') | |
printf "pass: %s\nhash: %s\n" "$PASS" "$HASH" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment