Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active January 17, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oprypin/a7bef68fc4804ba384178ee129465e74 to your computer and use it in GitHub Desktop.
Save oprypin/a7bef68fc4804ba384178ee129465e74 to your computer and use it in GitHub Desktop.
Check your passwords against https://haveibeenpwned.com/Passwords
# Check your passwords against https://haveibeenpwned.com/Passwords
# Usage:
# crystal check_passwords.cr -- pwned-passwords-sha1-ordered-by-hash*.txt
# Enter your passwords one per line, then press Return twice. Or pipe them in.
require "digest/sha1"
passwords = Array(String).new
until (line = gets(chomp: true) || "").empty?
passwords << line
end
ARGV.each do |filename|
File.open(filename) do |file|
passwords.each do |password|
hash = Digest::SHA1.hexdigest(password).upcase
(0u64...File.size(filename)).bsearch { |pos|
file.seek(pos)
# Find the beginning of the line.
pos -= 40 - file.read_line(':', chomp: true).size
file.seek(pos)
line = file.read_line(':', chomp: true)
raise "Malformed file" if line.size != 40
if line == hash
count = file.read_line(chomp: true)
puts "#{password} \u00D7#{count}"
break
end
line >= hash
}
end
end
end
@girng
Copy link

girng commented Jan 17, 2019

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment