Class: Unpwn

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

Constructor Details

#initialize(min: 8, max: nil) ⇒ Unpwn

Returns a new instance of Unpwn.

Raises:

  • (ArgumentError)


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

Returns:

  • (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

#bloomObject



29
30
31
32
33
34
# File 'lib/unpwn.rb', line 29

def bloom
  @bloom ||= begin
    top = File.read File.expand_path("top1000000.msgpack", __dir__)
    Bloomer.from_msgpack(top)
  end
end

#pwned?(password) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/unpwn.rb', line 25

def pwned?(password)
  bloom.include?(password) || Pwned.pwned?(password)
end