Class: Cryptophysh::PasswordGenerator
- Inherits:
-
Object
- Object
- Cryptophysh::PasswordGenerator
- Defined in:
- lib/cryptophysh/password_generator.rb
Constant Summary collapse
- DEFAULT_LENGTH =
12- DEFAULT_UPPERCASE =
true- DEFAULT_LOWERCASE =
true- DEFAULT_NUMBER_COUNT =
3- DEFAULT_SPECIAL_COUNT =
3- SPECIAL_CHARACTERS =
%w[@ % ! ? * ^ &].freeze
Instance Method Summary collapse
-
#generate_password ⇒ String
The generated password of @length characters.
-
#initialize(length: DEFAULT_LENGTH, uppercase: DEFAULT_UPPERCASE, lowercase: DEFAULT_LOWERCASE, number: DEFAULT_NUMBER_COUNT, special: DEFAULT_SPECIAL_COUNT) ⇒ Cryptophysh::PasswordGenerator
constructor
Instantiatates a new PasswordGenerator instance.
Constructor Details
#initialize(length: DEFAULT_LENGTH, uppercase: DEFAULT_UPPERCASE, lowercase: DEFAULT_LOWERCASE, number: DEFAULT_NUMBER_COUNT, special: DEFAULT_SPECIAL_COUNT) ⇒ Cryptophysh::PasswordGenerator
Instantiatates a new PasswordGenerator instance.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cryptophysh/password_generator.rb', line 22 def initialize( length: DEFAULT_LENGTH, uppercase: DEFAULT_UPPERCASE, lowercase: DEFAULT_LOWERCASE, number: DEFAULT_NUMBER_COUNT, special: DEFAULT_SPECIAL_COUNT ) @length = length @uppercase = uppercase @lowercase = lowercase @number = number @special = special validate_attributes end |
Instance Method Details
#generate_password ⇒ String
Returns the generated password of @length characters.
39 40 41 42 43 44 45 |
# File 'lib/cryptophysh/password_generator.rb', line 39 def generate_password password = "" @special.times { password += SPECIAL_CHARACTERS.sample } password += number_string if @number > 0 password += character_string(@length - password.size) password.chars.shuffle.join end |