Module: Randpass
- Defined in:
- lib/randpass/random.rb,
lib/randpass/version.rb
Overview
Note:
Always shuffle #base64 if it has less than 16 chars, because they end with ‘==’
Generate random password with SecureRandom#base64 and a few random special characters. Method #randpass is defined as class and instance method, so you can call it or include it.
Constant Summary collapse
- VERSION =
gem version
'0.1.2'
Class Method Summary collapse
- .randpass(number_of_chars) ⇒ String (also: [])
Instance Method Summary collapse
-
#randpass(number_of_chars) ⇒ String
Random number of times try to add random special character.
Class Method Details
.randpass(number_of_chars) ⇒ String Also known as: []
25 26 27 28 29 30 31 |
# File 'lib/randpass/random.rb', line 25 def randpass(number_of_chars) param = SecureRandom.base64(number_of_chars) rand(5..10).times do param = add_special_chars(param) end param.split('').shuffle.join end |
Instance Method Details
#randpass(number_of_chars) ⇒ String
Random number of times try to add random special character. Transform to array, shuffle, and join back to string
19 20 21 |
# File 'lib/randpass/random.rb', line 19 def randpass(number_of_chars) Randpass[number_of_chars] end |