Created
February 3, 2021 12:11
-
-
Save jeroenhe/1db061763c913db923e9e72dedabcc05 to your computer and use it in GitHub Desktop.
Check whether a linux bcrypt password hash matches with a plain-text password
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 | |
| read -p "Username >" username | |
| IFS= read -p "Password >" password | |
| salt=$(sudo getent shadow $username | cut -d$ -f3) | |
| epassword=$(sudo getent shadow $username | cut -d: -f2) | |
| match=$(python3 -c 'import crypt; print(crypt.crypt("'"${password}"'", "$6$'${salt}'"))') | |
| echo "salt=$salt" | |
| echo "match=$match" | |
| echo "epassword=$epassword" | |
| [ ${match} == ${epassword} ] && echo "Password matches" || echo "Password doesn't match" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment