Last active
January 7, 2024 17:36
-
-
Save aquila12/2210309ea7b4b9785ff06a5572342aa0 to your computer and use it in GitHub Desktop.
A really simple Ruby script to check password pwnage (because https://github.com/philnash/pwned isn't simple enough)
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
#!/usr/bin/env ruby | |
# Checks whether passwords have been pwned | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'excon' | |
end | |
require 'csv' | |
require 'digest' | |
PP = Excon.new('https://api.pwnedpasswords.com', persistent: true) | |
def check_password(password) | |
password.chomp! | |
hash = Digest::SHA1.hexdigest(password) | |
prefix = hash.slice!(0..4) | |
key = "#{hash.upcase}:" | |
rows = PP.get(path: "/range/#{prefix}").body.lines | |
result = rows.bsearch { |r| r >= key } | |
return unless result&.start_with? key | |
count = result.split(':').last.to_i | |
puts "#{password}:#{count}" | |
end | |
# Read a firefox exported logins.csv | |
if ARGV.first == '--ff' | |
ARGV.shift | |
CSV.foreach(ARGV.shift, headers: true) { |r| check_password r['password'] } | |
# Iterate any files specified on the command line; or stdin | |
else | |
ARGF.each_line { |p| check_password p } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to add: