Module: Randpass

Defined in:
lib/randpass/random.rb,
lib/randpass.rb,
lib/randpass/version.rb

Overview

Generate random password with base64 and few random special characters

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.[](number_of_chars = 18) ⇒ Object Also known as: randpass

Note:

Always shuffle #base64 if it has less than 16 chars, because they end with ‘==’

Add special characters to base64 random string, and shuffle it



13
14
15
16
17
# File 'lib/randpass/random.rb', line 13

def [](number_of_chars = 18)
  param = SecureRandom.base64(number_of_chars)
  rand(5..10).times { param = add_special_chars(param) }
  param.split('').shuffle.join
end