Module: PasswordStrength

Defined in:
lib/password_strength.rb,
lib/password_strength/base.rb,
lib/password_strength/engine.rb,
lib/password_strength/version.rb,
lib/password_strength/validators/windows2008.rb

Defined Under Namespace

Modules: Validators, Version Classes: Base, Engine

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enabledObject

You can disable PasswordStrength without having to change a single line of code. This is specially great on development environment.



40
41
42
# File 'lib/password_strength.rb', line 40

def enabled
  @enabled
end

Class Method Details

.test(username, password, options = {}) ⇒ Object

Test the password strength by applying several rules. The username is required to match its substring in passwords.

strength = PasswordStrength.test("johndoe", "mypass")
strength.weak?
#=> true

You can provide an options hash.

strength = PasswordStrength.test("johndoe", "^Str0ng P4ssw0rd$", :exclude => /\s/)
strength.status
#=> :invalid

strength.invalid?
#=> true

You can also provide an array.

strength = PasswordStrength.test("johndoe", "^Str0ng P4ssw0rd$", :exclude => [" ", "asdf", "123"])


31
32
33
34
35
# File 'lib/password_strength.rb', line 31

def self.test(username, password, options = {})
  strength = Base.new(username, password, options)
  strength.test
  strength
end