Last active
February 26, 2021 11:28
-
-
Save tomasbasham/6628f7a70bdb5a2ffc4e021bfb566778 to your computer and use it in GitHub Desktop.
This file contains 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
require 'digest' | |
require 'net/http' | |
password = ARGV[0] || 'Password' | |
hashed_password = Digest::SHA1.hexdigest password | |
# SHA1 hashes will be 40 characters long | |
prefix = hashed_password[0, 5].to_s.upcase # Get the first 5 characters | |
suffix = hashed_password[5..-1].to_s.upcase # Get the remaining 35 characters | |
puts "checking pwnedpasswords.com for: #{password}" | |
uri = URI("https://api.pwnedpasswords.com/range/#{prefix}") | |
res = Net::HTTP.get(uri) | |
puts res.split("\n").find { |pwned_password| | |
pwned_password.start_with? suffix | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment