Sha256: c65b5d3f5075be8924f4f2741a56d4499f91946999f12e214eab322dff343477

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

#!/usr/bin/env ruby

require "pwned"
require "optparse"
require "io/console"

options = {}
parser = OptionParser.new do |opts|
  opts.banner = <<-USAGE
Usage: pwned <password>

Tests a password against the Pwned Passwords API using the k-anonymity model,
which avoids sending the entire password to the service.opts

If the password has been found in a publicly available breach then this tool
will report how many times it has been seen. Otherwise the tool will report that
the password has not been found in a public breach yet.

USAGE

  opts.version = Pwned::VERSION

  opts.on("-s", "--secret", "Enter password without displaying characters.\n#{" "* 37}Overrides provided arguments.")
  opts.on_tail("-h", "--help", "Show help.")
  opts.on_tail("-v", "--version", "Show version number.\n\n")
end

parser.parse!(ARGV, into: options)

if options[:help]
  puts parser.help
  exit
end
if options[:version]
  puts parser.ver
  exit
end
password_to_test = ARGV.first
if options[:secret]
  password_to_test = STDIN.getpass("Password: ")
end
if !password_to_test || password_to_test.strip == ""
  puts parser.help
  exit
end
password = Pwned::Password.new(password_to_test || ARGV.first)
if password.pwned?
  puts "Pwned!\nThe password has been found in public breaches #{password.pwned_count} times."
else
  puts "The password has not been found in a public breach."
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pwned-2.4.1 bin/pwned
pwned-2.4.0 bin/pwned
pwned-2.3.0 bin/pwned
pwned-2.2.0 bin/pwned
pwned-2.1.0 bin/pwned