Module: Pwned

Defined in:
lib/pwned.rb,
lib/pwned/error.rb,
lib/pwned/version.rb,
lib/pwned/password.rb

Overview

The main namespace for Pwned. Includes convenience methods for getting the results for a password.

Defined Under Namespace

Classes: Error, Password, TimeoutError

Constant Summary

VERSION =

The current version of the pwned gem.

"1.1.0"

Class Method Summary collapse

Class Method Details

.pwned?(password, request_options = {}) ⇒ Boolean

Returns true when the password has been pwned.

Examples:

Pwned.pwned?("password") #=> true
Pwned.pwned?("pwned::password") #=> false

Parameters:

  • password (String)

    The password you want to check against the API.

  • request_options (Hash) (defaults to: {})

    Options that can be passed to open when calling the API

Options Hash (request_options):

  • 'User-Agent' (String) — default: "Ruby Pwned::Password #{Pwned::VERSION}"

    The user agent used when making an API request.

Returns:

  • (Boolean)

    Whether the password appears in the data breaches or not.

Since:

  • 1.1.0



38
39
40
# File 'lib/pwned.rb', line 38

def self.pwned?(password, request_options={})
  Pwned::Password.new(password, request_options).pwned?
end

.pwned_count(password, request_options = {}) ⇒ Integer

Returns number of times the password has been pwned.

Examples:

Pwned.pwned_count("password") #=> 3303003
Pwned.pwned_count("pwned::password") #=> 0

Parameters:

  • password (String)

    The password you want to check against the API.

  • request_options (Hash) (defaults to: {})

    Options that can be passed to open when calling the API

Options Hash (request_options):

  • 'User-Agent' (String) — default: "Ruby Pwned::Password #{Pwned::VERSION}"

    The user agent used when making an API request.

Returns:

  • (Integer)

    The number of times the password has appeared in the data breaches.

Since:

  • 1.1.0



57
58
59
# File 'lib/pwned.rb', line 57

def self.pwned_count(password, request_options={})
  Pwned::Password.new(password, request_options).pwned_count
end