Class: StrongPassword::QwertyAdjuster
- Inherits:
-
Object
- Object
- StrongPassword::QwertyAdjuster
- Defined in:
- lib/strong_password/qwerty_adjuster.rb
Constant Summary collapse
- QWERTY_STRINGS =
[ "1234567890-", "qwertyuiop", "asdfghjkl;", "zxcvbnm,./", "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik,9ol.0p;/-['=]:?_{\"+}", "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9ol0p", "qazwsxedcrfvtgbyhnujmik,ol.p;/-['=]:?_{\"+}", "qazwsxedcrfvtgbyhnujmikolp", "]\"/=[;.-pl,0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1", "pl0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1", "]\"/[;.pl,okmijnuhbygvtfcrdxeszwaq", "plokmijnuhbygvtfcrdxeszwaq", "014725836914702583697894561230258/369*+-*/", "abcdefghijklmnopqrstuvwxyz" ]
Instance Attribute Summary collapse
-
#base_password ⇒ Object
readonly
Returns the value of attribute base_password.
Instance Method Summary collapse
-
#adjusted_entropy(entropy_threshhold: 0) ⇒ Object
Returns the minimum entropy for the password’s qwerty locality adjustments.
-
#initialize(password) ⇒ QwertyAdjuster
constructor
A new instance of QwertyAdjuster.
- #is_strong?(min_entropy: 18) ⇒ Boolean
- #is_weak?(min_entropy: 18) ⇒ Boolean
Constructor Details
#initialize(password) ⇒ QwertyAdjuster
Returns a new instance of QwertyAdjuster.
22 23 24 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 22 def initialize(password) @base_password = password.downcase end |
Instance Attribute Details
#base_password ⇒ Object (readonly)
Returns the value of attribute base_password.
20 21 22 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 20 def base_password @base_password end |
Instance Method Details
#adjusted_entropy(entropy_threshhold: 0) ⇒ Object
Returns the minimum entropy for the password’s qwerty locality adjustments. If a threshhold is specified we will bail early to avoid unnecessary processing.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 37 def adjusted_entropy(entropy_threshhold: 0) revpassword = base_password.reverse min_entropy = [EntropyCalculator.calculate(base_password), EntropyCalculator.calculate(revpassword)].min QWERTY_STRINGS.each do |qwertystr| qpassword = mask_qwerty_strings(base_password, qwertystr) qrevpassword = mask_qwerty_strings(revpassword, qwertystr) if qpassword != base_password numbits = EntropyCalculator.calculate(qpassword) min_entropy = [min_entropy, numbits].min return min_entropy if min_entropy < entropy_threshhold end if qrevpassword != revpassword numbits = EntropyCalculator.calculate(qrevpassword) min_entropy = [min_entropy, numbits].min return min_entropy if min_entropy < entropy_threshhold end end min_entropy end |
#is_strong?(min_entropy: 18) ⇒ Boolean
26 27 28 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 26 def is_strong?(min_entropy: 18) adjusted_entropy(entropy_threshhold: min_entropy) >= min_entropy end |
#is_weak?(min_entropy: 18) ⇒ Boolean
30 31 32 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 30 def is_weak?(min_entropy: 18) !is_strong?(min_entropy: min_entropy) end |