Advertisement
Guest User

Passcheck.sh

a guest
Apr 26th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.65 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ###
  4. # Checks provided password against breach database
  5. ###
  6.  
  7. function pc() {
  8.  if [[ -z $@ ]]; then
  9.    echo -n Password:
  10.    read -s password
  11.  else
  12.    password="$@"
  13.  fi
  14.  hash="$(echo -n $password | openssl sha1 | awk '{print $2}')"
  15.  upperCase="$(echo $hash | tr '[a-z]' '[A-Z]')"
  16.  prefix="${upperCase:0:5}"
  17.  response=$(curl -s https://api.pwnedpasswords.com/range/$prefix)
  18.  while read -r line; do
  19.    lineOriginal="$prefix$line"
  20.    if [ "${lineOriginal:0:40}" == "$upperCase" ]; then
  21.      echo -e "\nPassword breached."
  22.      return 1;
  23.    fi
  24.  done <<< "$response"
  25.  echo -e "\nPassword not found in breached database."
  26. }
  27.  
  28. pc "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement