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.2.0"
Instance Method Summary collapse
- #acceptable?(password) ⇒ Boolean
- #bloom ⇒ Object
-
#initialize(min: 8, max: nil) ⇒ Unpwn
constructor
A new instance of Unpwn.
- #pwned?(password) ⇒ Boolean
Constructor Details
#initialize(min: 8, max: nil) ⇒ Unpwn
Returns a new instance of Unpwn.
10 11 12 13 14 15 16 |
# File 'lib/unpwn.rb', line 10 def initialize(min: 8, max: nil) raise ArgumentError if min && min < 8 raise ArgumentError if max && max < 64 @min = min @max = max end |
Instance Method Details
#acceptable?(password) ⇒ Boolean
18 19 20 21 22 23 |
# File 'lib/unpwn.rb', line 18 def acceptable?(password) return false if @min && password.size < @min return false if @max && password.size > @max !pwned?(password) end |
#bloom ⇒ Object
29 30 31 32 33 34 |
# File 'lib/unpwn.rb', line 29 def bloom @bloom ||= begin top = File.read File.("top1000000.msgpack", __dir__) Bloomer.from_msgpack(top) end end |
#pwned?(password) ⇒ Boolean
25 26 27 |
# File 'lib/unpwn.rb', line 25 def pwned?(password) bloom.include?(password) || Pwned.pwned?(password) end |