Module: PasswordUtils

Extended by:
PasswordUtils
Included in:
PasswordUtils
Defined in:
lib/protected/password_utils.rb

Constant Summary collapse

SpecialCharacters =
%w(! @ # $ % ^ & + =)
LowercaseLetters =
('a'..'z').to_a
UppercaseLetters =
('A'..'Z').to_a
Numbers =
('0'..'9').to_a
PasswordLength =
8

Instance Method Summary collapse

Instance Method Details

#generate_random_passwordObject



25
26
27
28
# File 'lib/protected/password_utils.rb', line 25

def generate_random_password
  password = generate_random(PasswordLength) until strong?(password)
  password
end

#strong?(str) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
# File 'lib/protected/password_utils.rb', line 16

def strong?(str)
  return false if str.blank?
  return false unless str =~ Regexp.union(*SpecialCharacters)
  return false unless str =~ Regexp.union(*LowercaseLetters)
  return false unless str =~ Regexp.union(*UppercaseLetters)
  return false unless str =~ Regexp.union(*Numbers)
  true
end