Class: HibpCheck
- Inherits:
-
Object
- Object
- HibpCheck
- Defined in:
- lib/hibp_check.rb,
lib/hibp_check/version.rb
Constant Summary collapse
- API_URL =
'https://api.pwnedpasswords.com/range/'
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#hashes ⇒ Object
readonly
Returns the value of attribute hashes.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#remainder ⇒ Object
readonly
Returns the value of attribute remainder.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ HibpCheck
constructor
A new instance of HibpCheck.
- #password_used(password) ⇒ Object
- #sha1_used(hashed) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ HibpCheck
Returns a new instance of HibpCheck.
11 12 13 |
# File 'lib/hibp_check.rb', line 11 def initialize(params={}) @params = params end |
Instance Attribute Details
#hashes ⇒ Object (readonly)
Returns the value of attribute hashes.
9 10 11 |
# File 'lib/hibp_check.rb', line 9 def hashes @hashes end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/hibp_check.rb', line 9 def params @params end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/hibp_check.rb', line 9 def prefix @prefix end |
#remainder ⇒ Object (readonly)
Returns the value of attribute remainder.
9 10 11 |
# File 'lib/hibp_check.rb', line 9 def remainder @remainder end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/hibp_check.rb', line 9 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/hibp_check.rb', line 9 def response @response end |
Instance Method Details
#password_used(password) ⇒ Object
15 16 17 18 |
# File 'lib/hibp_check.rb', line 15 def password_used(password) return nil if password.nil? sha1_used Digest::SHA1.hexdigest(password.to_s) end |
#sha1_used(hashed) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hibp_check.rb', line 20 def sha1_used(hashed) return nil unless hashed =~ /^[0-9a-f]{40}$/i @prefix = hashed.slice(0..4).upcase @remainder = hashed.slice(5..-1).upcase @hashes = fetch_hashes_by_prefix prefix if hashes return $1.to_i if hashes.match(/#{remainder}:(\d+)/) return 0 end nil end |