Skip to content

Instantly share code, notes, and snippets.

@jeroenhe
Created February 3, 2021 12:11
Show Gist options
  • Select an option

  • Save jeroenhe/1db061763c913db923e9e72dedabcc05 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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