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' ].freeze
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: min_entropy) ⇒ 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: min_entropy) ⇒ QwertyAdjuster
22 23 24 25 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 22 def initialize(min_entropy: 18, entropy_threshhold: min_entropy) @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 |
# File 'lib/strong_password/qwerty_adjuster.rb', line 38 def adjusted_entropy(base_password) revpassword = base_password.reverse lowest_entropy = [EntropyCalculator.calculate(base_password), EntropyCalculator.calculate(revpassword)].min # If our entropy is already lower than we care about then there's no reason to look further. return lowest_entropy if lowest_entropy < entropy_threshhold qpassword = mask_qwerty_strings(base_password) lowest_entropy = [lowest_entropy, EntropyCalculator.calculate(qpassword)].min if qpassword != base_password # Bail early if our entropy on the base password's masked qwerty value is less than our threshold. return lowest_entropy if lowest_entropy < entropy_threshhold qrevpassword = mask_qwerty_strings(revpassword) lowest_entropy = [lowest_entropy, EntropyCalculator.calculate(qrevpassword)].min if qrevpassword != revpassword lowest_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 |