Last active
June 9, 2020 15:54
-
-
Save hundredwatt/36f4e905bd34b8a2bd4b2942a9369754 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/sha1' | |
require 'net/http' | |
def pwned?(password) | |
digest = Digest::SHA1.hexdigest(password).upcase | |
prefix = digest[0,5] | |
suffix = digest[5,256] | |
uri = URI.parse("https://api.pwnedpasswords.com/range/" + prefix) | |
response = Net::HTTP.get_response(uri) | |
rows = response.body.split("\r\n").map { |i| i.split(":") }.each_with_object({}) { |(k,v), h| h[k] = v.to_i } | |
return !rows[suffix].nil? | |
end | |
root_part = ENV['ROOT_PART'].to_s | |
# Suffix length of 2 | |
letters = 'abcdefghijklmnopqrstuvwxyz'.split("") | |
suffixes = letters.map { |l1| letters.map { |l2| l1 + l2 } }.flatten | |
suffixes.each_with_index do |suffix, idx| | |
if pwned?(root_part + suffix) | |
p "pwned: " + suffix | |
end | |
# Report progress | |
p idx if idx % 25 == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment