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.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Unpwn.

Raises:

  • (ArgumentError)


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
  @request_options = request_options || {}
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



9
10
11
# File 'lib/unpwn.rb', line 9

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



9
10
11
# File 'lib/unpwn.rb', line 9

def min
  @min
end

#request_optionsObject (readonly)

Returns the value of attribute request_options.



9
10
11
# File 'lib/unpwn.rb', line 9

def request_options
  @request_options
end

Instance Method Details

#acceptable?(password) ⇒ Boolean

Returns:

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

#bloomObject



31
32
33
34
35
36
# File 'lib/unpwn.rb', line 31

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

#pwned?(password) ⇒ Boolean

Returns:

  • (Boolean)


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

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