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
-
#entropy_threshhold ⇒ Object
readonly
Returns the value of attribute entropy_threshhold.
-
#min_entropy ⇒ Object
readonly
Returns the value of attribute min_entropy.
Instance Method Summary collapse
-
#adjusted_entropy(base_password) ⇒ Object
Returns the minimum entropy for the password’s qwerty locality adjustments.
-
#initialize(min_entropy: 18, entropy_threshhold: 0) ⇒ QwertyAdjuster
constructor
A new instance of QwertyAdjuster.
- #is_strong?(base_password) ⇒ Boolean
- #is_weak?(base_password) ⇒ Boolean
Constructor Details
#initialize(min_entropy: 18, entropy_threshhold: 0) ⇒ QwertyAdjuster
Returns a new instance of QwertyAdjuster.
22 23 24 25 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 22 def initialize(min_entropy: 18, entropy_threshhold: 0) @min_entropy = min_entropy @entropy_threshhold = entropy_threshhold end |
Instance Attribute Details
#entropy_threshhold ⇒ Object (readonly)
Returns the value of attribute entropy_threshhold.
20 21 22 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 20 def entropy_threshhold @entropy_threshhold end |
#min_entropy ⇒ Object (readonly)
Returns the value of attribute min_entropy.
20 21 22 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 20 def min_entropy @min_entropy end |
Instance Method Details
#adjusted_entropy(base_password) ⇒ 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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 38 def adjusted_entropy(base_password) revpassword = base_password.reverse min_entropy = [EntropyCalculator.calculate(base_password), EntropyCalculator.calculate(revpassword)].min qpassword = mask_qwerty_strings(base_password) qrevpassword = mask_qwerty_strings(revpassword) 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 min_entropy end |
#is_strong?(base_password) ⇒ Boolean
27 28 29 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 27 def is_strong?(base_password) adjusted_entropy(base_password) >= min_entropy end |
#is_weak?(base_password) ⇒ Boolean
31 32 33 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 31 def is_weak?(base_password) !is_strong?(base_password) end |