Class: Pwned::Password
- Inherits:
-
Object
- Object
- Pwned::Password
- Defined in:
- lib/pwned/password.rb
Constant Summary collapse
- API_URL =
"https://api.pwnedpasswords.com/range/"
- HASH_PREFIX_LENGTH =
5
- DEFAULT_REQUEST_OPTIONS =
{ "User-Agent" => "Ruby Pwned::Password #{Pwned::VERSION}" }
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
Instance Method Summary collapse
- #hashed_password ⇒ Object
-
#initialize(password, request_options = {}) ⇒ Password
constructor
A new instance of Password.
- #pwned? ⇒ Boolean
- #pwned_count ⇒ Object
Constructor Details
#initialize(password, request_options = {}) ⇒ Password
Returns a new instance of Password.
14 15 16 17 |
# File 'lib/pwned/password.rb', line 14 def initialize(password, ={}) @password = password @request_options = DEFAULT_REQUEST_OPTIONS.merge() end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
12 13 14 |
# File 'lib/pwned/password.rb', line 12 def password @password end |
Instance Method Details
#hashed_password ⇒ Object
19 20 21 |
# File 'lib/pwned/password.rb', line 19 def hashed_password Digest::SHA1.hexdigest(password).upcase end |
#pwned? ⇒ Boolean
23 24 25 |
# File 'lib/pwned/password.rb', line 23 def pwned? !!match_data end |
#pwned_count ⇒ Object
27 28 29 |
# File 'lib/pwned/password.rb', line 27 def pwned_count match_data ? match_data[1].to_i : 0 end |