Module: Randpass
- Defined in:
- lib/randpass/random.rb,
lib/randpass/version.rb
Overview
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
- ARRAY =
Allowed specials. xxx is just a flag for #add_special_chars
%w[! # * $ % _ @ xxx].freeze
- VERSION =
gem version
'0.1.3'
Class Method Summary collapse
- .randpass(number_of_chars = 20) ⇒ String (also: [])
Instance Method Summary collapse
-
#randpass(number_of_chars = nil) ⇒ String
Random number of times try to add random special character.
Class Method Details
.randpass(number_of_chars = 20) ⇒ String Also known as: []
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/randpass/random.rb', line 28 def randpass(number_of_chars = 20) # slice string made with base64, to number of characters we want param = SecureRandom.base64(number_of_chars)[0...number_of_chars] rand(param.size / 2).times do param = add_special_characters(param) end param.split('').shuffle.join end |
Instance Method Details
#randpass(number_of_chars = nil) ⇒ String
Random number of times try to add random special character. Transform to array, shuffle, and join back to string.
Provide number of characters for password as argument, default value is 22.
22 23 24 |
# File 'lib/randpass/random.rb', line 22 def randpass(number_of_chars = nil) Randpass[number_of_chars] end |