Module: Zxcvbn::CrackTime

Included in:
Scorer
Defined in:
lib/zxcvbn/crack_time.rb

Constant Summary collapse

SINGLE_GUESS =
0.010
NUM_ATTACKERS =
100
SECONDS_PER_GUESS =
SINGLE_GUESS / NUM_ATTACKERS

Instance Method Summary collapse

Instance Method Details

#crack_time_to_score(seconds) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zxcvbn/crack_time.rb', line 14

def crack_time_to_score(seconds)
  if seconds < 10**2
    0
  elsif seconds < 10**4
    1
  elsif seconds < 10**6
    2
  elsif seconds < 10**8
    3
  else
    4
  end
end

#display_time(seconds) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/zxcvbn/crack_time.rb', line 28

def display_time(seconds)
  minute  = 60
  hour    = minute * 60
  day     = hour * 24
  month   = day * 31
  year    = month * 12
  century = year * 100

  if seconds < minute
    'instant'
  elsif seconds < hour
    "#{1 + (seconds / minute).ceil} minutes"
  elsif seconds < day
    "#{1 + (seconds / hour).ceil} hours"
  elsif seconds < month
    "#{1 + (seconds / day).ceil} days"
  elsif seconds < year
    "#{1 + (seconds / month).ceil} months"
  elsif seconds < century
    "#{1 + (seconds / year).ceil} years"
  else
    'centuries'
  end
end

#entropy_to_crack_time(entropy) ⇒ Object



10
11
12
# File 'lib/zxcvbn/crack_time.rb', line 10

def entropy_to_crack_time(entropy)
  0.5 * (2**entropy) * SECONDS_PER_GUESS
end