Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ###
- # Checks provided password against breach database
- ###
- function pc() {
- if [[ -z $@ ]]; then
- echo -n Password:
- read -s password
- else
- password="$@"
- fi
- hash="$(echo -n $password | openssl sha1 | awk '{print $2}')"
- upperCase="$(echo $hash | tr '[a-z]' '[A-Z]')"
- prefix="${upperCase:0:5}"
- response=$(curl -s https://api.pwnedpasswords.com/range/$prefix)
- while read -r line; do
- lineOriginal="$prefix$line"
- if [ "${lineOriginal:0:40}" == "$upperCase" ]; then
- echo -e "\nPassword breached."
- return 1;
- fi
- done <<< "$response"
- echo -e "\nPassword not found in breached database."
- }
- pc "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement