Module: Pwned::PasswordBase
- Included in:
- HashedPassword, Password
- Defined in:
- lib/pwned/password_base.rb
Overview
This class represents a password. It does all the work of talking to the Pwned Passwords API to find out if the password has been pwned.
Constant Summary collapse
- API_URL =
The base URL for the Pwned Passwords API
"https://api.pwnedpasswords.com/range/"
- HASH_PREFIX_LENGTH =
The number of characters from the start of the hash of the password that are used to search for the range of passwords.
5
- SHA1_LENGTH =
The total length of a SHA1 hash
40
- DEFAULT_REQUEST_HEADERS =
The default request headers that are used to make HTTP requests to the API. A user agent is provided as requested in the documentation.
{ "User-Agent" => "Ruby Pwned::Password #{Pwned::VERSION}" }.freeze
Instance Attribute Summary collapse
-
#hashed_password ⇒ String
readonly
Returns the full SHA1 hash of the given password in uppercase.
Instance Method Summary collapse
-
#pwned? ⇒ Boolean
true
when the password has been pwned. -
#pwned_count ⇒ Integer
The number of times the password has been pwned.
Instance Attribute Details
#hashed_password ⇒ String (readonly)
Returns the full SHA1 hash of the given password in uppercase.
64 65 66 |
# File 'lib/pwned/password_base.rb', line 64 def hashed_password @hashed_password end |
Instance Method Details
#pwned? ⇒ Boolean
Returns true
when the password has been pwned.
43 44 45 |
# File 'lib/pwned/password_base.rb', line 43 def pwned? pwned_count > 0 end |
#pwned_count ⇒ Integer
Returns the number of times the password has been pwned.
56 57 58 |
# File 'lib/pwned/password_base.rb', line 56 def pwned_count @pwned_count ||= fetch_pwned_count end |