Class: Unpwn
- Inherits:
-
Object
- Object
- Unpwn
- Defined in:
- lib/unpwn.rb,
lib/unpwn/version.rb
Overview
Unpwn.pwned? tells you if a password should be rejected.
Constant Summary collapse
- VERSION =
"0.3.0"
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#request_options ⇒ Object
readonly
Returns the value of attribute request_options.
Instance Method Summary collapse
- #acceptable?(password) ⇒ Boolean
- #bloom ⇒ Object
-
#initialize(min: 8, max: nil, request_options: nil) ⇒ Unpwn
constructor
A new instance of Unpwn.
- #pwned?(password) ⇒ Boolean
Constructor Details
#initialize(min: 8, max: nil, request_options: nil) ⇒ Unpwn
Returns a new instance of Unpwn.
11 12 13 14 15 16 17 18 |
# File 'lib/unpwn.rb', line 11 def initialize(min: 8, max: nil, request_options: nil) raise ArgumentError if min && min < 8 raise ArgumentError if max && max < 64 @min = min @max = max = || {} end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
9 10 11 |
# File 'lib/unpwn.rb', line 9 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
9 10 11 |
# File 'lib/unpwn.rb', line 9 def min @min end |
#request_options ⇒ Object (readonly)
Returns the value of attribute request_options.
9 10 11 |
# File 'lib/unpwn.rb', line 9 def end |
Instance Method Details
#acceptable?(password) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/unpwn.rb', line 20 def acceptable?(password) return false if min && password.size < min return false if max && password.size > max !pwned?(password) end |
#bloom ⇒ Object
31 32 33 34 35 36 |
# File 'lib/unpwn.rb', line 31 def bloom @bloom ||= begin top = File.read File.("top1000000.msgpack", __dir__) Bloomer.from_msgpack(top) end end |
#pwned?(password) ⇒ Boolean
27 28 29 |
# File 'lib/unpwn.rb', line 27 def pwned?(password) bloom.include?(password) || Pwned.pwned?(password, ) end |