rice

personal dot files and scripts for linux and macOS
Log | Files | Refs | README | LICENSE

pash_check (627B)


      1 #!/bin/sh -e
      2 
      3 sread() {
      4     printf '%s: ' "$2"
      5 
      6     # Disable terminal printing while the user inputs their
      7     # password. POSIX 'read' has no '-s' flag which would
      8     # effectively do the same thing.
      9     stty -echo
     10     read -r "$1"
     11     stty echo
     12 
     13     printf '\n'
     14 }
     15 
     16 [ -t 0 ] && sread pass "Enter password" || read -r pass
     17 
     18 sha_pass=$(echo $pass | sha1sum | cut -d' ' -f1 |  tr '[a-z]' '[A-Z]')
     19 sha_head=${sha_pass:0:5}
     20 sha_tail=${sha_pass:5}
     21 
     22 results=$(curl -s https://api.pwnedpasswords.com/range/$sha_head | grep $sha_tail | cut -d: -f2)
     23 [ "$results" = "" ] && echo "Password not found" || echo "Password found: $results"