Class: Pwned::Password

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, request_options={})
  @password = password
  @request_options = DEFAULT_REQUEST_OPTIONS.merge(request_options)
end

Instance Attribute Details

#passwordObject (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_passwordObject



19
20
21
# File 'lib/pwned/password.rb', line 19

def hashed_password
  Digest::SHA1.hexdigest(password).upcase
end

#pwned?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pwned/password.rb', line 23

def pwned?
  !!match_data
end

#pwned_countObject



27
28
29
# File 'lib/pwned/password.rb', line 27

def pwned_count
  match_data ? match_data[1].to_i : 0
end