Created
June 17, 2014 05:36
-
-
Save anonymous/e168a8b46b9a8a5c7d24 to your computer and use it in GitHub Desktop.
password and hash generation with apg, htpasswd/bcrypt
This file contains 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 | |
# usage: | |
# source this file or include the passnhash function in your .bash_profile/.bashrc | |
# then: `passnhash 0:35:500:14` | |
# prerequisites: | |
# 1) recent version of htpasswd that supports bcrypt (-B flag) | |
# deb: `apt-get install apache2-utils` | |
# mac: `brew install 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 ALG=$(echo "$@" | awk -F: '{ print $1 }') | |
local LEN=$(echo "$@" | awk -F: '{ print $2 }') | |
local RND=$(echo "$@" | awk -F: '{ print $3 }') | |
local CST=$(echo "$@" | awk -F: '{ print $4 }') | |
local PAS=$(apg -a "$ALG" -m "$LEN" -n "$RND" | tail -n 1) | |
# "username" is a placeholder value since we're only interested in the hash | |
local HAS=$(echo "$PAS" | htpasswd -n -i -B -C "$CST" username | tr -d '\n' | awk -F: '{ print $2 }') | |
printf "password: %s\nhash: %s\n" "$PAS" "$HAS" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment