module Pwned
The main namespace for Pwned
. Includes convenience methods for getting the results for a password.
Constants
- VERSION
The current version of the
pwned
gem.
Public Class Methods
Returns the full SHA1 hash of the given password in uppercase. This can be safely passed around your code before making the pwned request (e.g. dropped into a queue table).
@example
Pwned.hash_password("password") #=> 5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8
@param password [String] The password you want to check against the API @return [String] An uppercase SHA1 hash of the password @since 2.1.0
# File lib/pwned.rb, line 79 def self.hash_password(password) Digest::SHA1.hexdigest(password).upcase end
Returns true
when the password has been pwned.
@example
Pwned.pwned?("password") #=> true Pwned.pwned?("pwned::password") #=> false
@param password [String] The password you want to check against the API. @param [Hash] request_options Options that can be passed to Net::HTTP.start
when
calling the API
@option request_options [Symbol] :headers ({ “User-Agent” => “Ruby Pwned::Password
#{Pwned::VERSION}” })
HTTP headers to include in the request
@option request_options [Symbol] :ignore_env_proxy (false) The library
will try to infer an HTTP proxy from the `http_proxy` environment variable. If you do not want this behaviour, set this option to true.
@return [Boolean] Whether the password appears in the data breaches or not. @since 1.1.0
# File lib/pwned.rb, line 43 def self.pwned?(password, request_options={}) Pwned::Password.new(password, request_options).pwned? end
Returns number of times the password has been pwned.
@example
Pwned.pwned_count("password") #=> 3303003 Pwned.pwned_count("pwned::password") #=> 0
@param password [String] The password you want to check against the API. @param [Hash] request_options Options that can be passed to Net::HTTP.start
when
calling the API
@option request_options [Symbol] :headers ({ “User-Agent” => “Ruby Pwned::Password
#{Pwned::VERSION}” })
HTTP headers to include in the request
@option request_options [Symbol] :ignore_env_proxy (false) The library
will try to infer an HTTP proxy from the `http_proxy` environment variable. If you do not want this behaviour, set this option to true.
@return [Integer] The number of times the password has appeared in the data
breaches.
@since 1.1.0
# File lib/pwned.rb, line 65 def self.pwned_count(password, request_options={}) Pwned::Password.new(password, request_options).pwned_count end