Class: PasswordStrength::Validators::Windows2008

Inherits:
Base
  • Object
show all
Defined in:
lib/password_strength/validators/windows2008.rb

Overview

Validates a Windows 2008 password against the following rules:

  • Passwords cannot contain the user’s account name or parts of the user’s full name that exceed two consecutive characters.

  • Passwords must be at least six characters in length.

  • Passwords must contain characters from three of the following four categories: English uppercase characters (A through Z); English lowercase characters (a through z); Base 10 digits (0 through 9); Non-alphabetic characters (for example, !, $, #, %).

Reference: technet.microsoft.com/en-us/library/cc264456.aspx

Constant Summary

Constants inherited from Base

Base::GOOD, Base::INVALID, Base::MULTIPLE_NUMBERS_RE, Base::MULTIPLE_SYMBOLS_RE, Base::STRONG, Base::SYMBOL_RE, Base::UPPERCASE_LOWERCASE_RE, Base::WEAK

Instance Attribute Summary

Attributes inherited from Base

#exclude, #password, #record, #score, #status, #username

Instance Method Summary collapse

Methods inherited from Base

#common_word?, common_words, #contain_invalid_matches?, #contain_invalid_repetion?, #good!, #good?, #initialize, #invalid!, #invalid?, #repetitions, #score_for, #sequences, #strong!, #strong?, #valid?, #weak!, #weak?

Constructor Details

This class inherits a constructor from PasswordStrength::Base

Instance Method Details

#password_contains_username?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'lib/password_strength/validators/windows2008.rb', line 27

def password_contains_username?
  0.upto(password.size - 1) do |i|
    substring = password[i, 3]
    return true if username.include?(substring)
  end

  false
end

#testObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/password_strength/validators/windows2008.rb', line 12

def test
  return invalid! if password.size < 6

  variety = 0
  variety += 1 if password =~ /[A-Z]/
  variety += 1 if password =~ /[a-z]/
  variety += 1 if password =~ /[0-9]/
  variety += 1 if password =~ PasswordStrength::Base::SYMBOL_RE

  return invalid! if variety < 3
  return invalid! if password_contains_username?

  strong!
end