Created
August 26, 2018 15:35
-
-
Save gzm55/b9ec9152dbaa5be84a2987f82de37a10 to your computer and use it in GitHub Desktop.
4 ways for generating crypt(3) hash for passwd
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
salt_pattern='0-9a-zA-Z./' | |
randompwd() { LC_CTYPE=C tr -dc ${2:-'A-Za-z0-9_!@%^&*/-+=.?'} < /dev/urandom | head -c ${1:-16} | xargs; } | |
rand_salt() { | |
randompwd 16 "salt_pattern" | |
} | |
round= | |
salt=/SSSSSS/ | |
method=6 | |
passwd=1 | |
crypt_mkpasswd() { | |
local r=$round | |
[ x$r != x5000 ] || unset r | |
mkpasswd -m sha-512 ${r:+-R $r} "$passwd" `echo -n $salt | head -c 16` | |
} | |
crypt_cryptpw() { | |
local r=$round | |
[ x$r != x5000 ] || unset r | |
cryptpw "$passwd" -S "${r:+rounds=$r$}${salt:+"$salt"}" | |
} | |
crypt_python() { | |
local r=$round | |
[ x$r != x5000 ] || unset r | |
local s="${salt//\\/\\\\}" | |
s="${s//'/\\'}" | |
python -c "import crypt; print crypt.crypt(\"$passwd\", '\$6${r:+\$rounds=$r}${s:+\$$s}\$')" | |
} | |
crypt_perl() { | |
local r=$round | |
[ x$r != x5000 ] || unset r | |
local s="${salt//\\/\\\\}" | |
s="${s//'/\\'}" | |
perl -e "print crypt('$passwd', '\$6${r:+\$rounds=$r}${s:+\$$s}\$').\"\\n\"" | |
} | |
t() { | |
cat <<END | |
mkpasswd: `crypt_mkpasswd` | |
cryptpw : `crypt_cryptpw` | |
python : `crypt_python` | |
perl : `crypt_perl` | |
END | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment