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
- #crack_time_to_score(seconds) ⇒ Object
- #display_time(seconds) ⇒ Object
- #entropy_to_crack_time(entropy) ⇒ Object
Instance Method Details
#crack_time_to_score(seconds) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/zxcvbn/crack_time.rb', line 11 def crack_time_to_score(seconds) case when seconds < 10**2 0 when seconds < 10**4 1 when seconds < 10**6 2 when seconds < 10**8 3 else 4 end end |
#display_time(seconds) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zxcvbn/crack_time.rb', line 26 def display_time(seconds) minute = 60 hour = minute * 60 day = hour * 24 month = day * 31 year = month * 12 century = year * 100 case when seconds < minute 'instant' when seconds < hour "#{1 + (seconds / minute).ceil} minutes" when seconds < day "#{1 + (seconds / hour).ceil} hours" when seconds < month "#{1 + (seconds / day).ceil} days" when seconds < year "#{1 + (seconds / month).ceil} months" when seconds < century "#{1 + (seconds / year).ceil} years" else 'centuries' end end |
#entropy_to_crack_time(entropy) ⇒ Object
7 8 9 |
# File 'lib/zxcvbn/crack_time.rb', line 7 def entropy_to_crack_time(entropy) 0.5 * (2 ** entropy) * SECONDS_PER_GUESS end |