Last active
December 15, 2018 22:56
-
-
Save wknapik/6ddd70745cc21af0f4114f5a90ddcd9f to your computer and use it in GitHub Desktop.
Generate password hash for Hippo CMS
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
Generate password hash for Hippo CMS. | |
# Requires bash and coreutils, slow. | |
./hippohash.sh <password> [salt] | |
# Requires python, fast. | |
./hippohash.py <password> [salt] |
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
#!/usr/bin/env python | |
import sys | |
from string import ascii_letters | |
from random import choice | |
from hashlib import sha256 | |
from base64 import b64encode | |
def hippohash(passwd, salt = ''.join(choice(ascii_letters) for _ in range(8))): | |
digest = None | |
for i in range(1040): | |
md = sha256() | |
md.update(digest or (salt + passwd).encode()) | |
digest = md.digest() | |
suf = (b64encode(e).decode() for e in (salt.encode(), digest)) | |
return "$SHA-256${}${}".format(*suf) | |
print(hippohash(*sys.argv[1:])) |
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
#!/usr/bin/env bash | |
set -eEo pipefail | |
shopt -s inherit_errexit >/dev/null 2>&1 || true | |
# $@ := pass salt | |
hippohash() { | |
local -r pass="${1:?}" salt="${2:?}" | |
local digest | |
# https://stackoverflow.com/questions/1604765/#answer-26094758 | |
hex2bin() { local c; while read -rN2 c; do echo -en "\x$c"; done; } | |
digest="$(echo -n "$salt$pass"|sha256sum)" | |
for ((i=0; i<1039; i++)) do | |
digest="$(echo -n "${digest% *}"|hex2bin|sha256sum)" | |
done | |
echo "\$SHA-256\$$(echo -n "$salt"|base64)\$$(echo -n "${digest% *}"|hex2bin|base64)" | |
} | |
hippohash "$1" "${2:-$((RANDOM))$((RANDOM))}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment