Class: BBMB::Util::PasswordGenerator
- Inherits:
-
Object
- Object
- BBMB::Util::PasswordGenerator
- Defined in:
- lib/bbmb/util/password_generator.rb
Constant Summary collapse
- SEQUENCE =
[ :char, :char, :sym, :num ]
- SIZE =
{ :char => 2, :num => 4, :sym => 1, }
- POOL =
{ :char => ("A".."Z").to_a + ("a".."z").to_a, :num => ("0".."9").to_a, :sym => %w{! @ * ?}, }
Class Method Summary collapse
Class Method Details
.generate(user) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bbmb/util/password_generator.rb', line 19 def generate(user) pool = POOL.dup char = [user.organisation, user.firstname, user.lastname].join if(char.length >= 12) pool[:char] = char.scan(/\w/) end pass = "" random_sequence.each { |type| SIZE[type].times { pass << pool[type].at(rand(pool[type].size)) } } pass end |
.random_sequence ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/bbmb/util/password_generator.rb', line 33 def random_sequence sequence = SEQUENCE.dup random = [] while(sequence.length > 0) random.push(sequence.delete_at(rand(sequence.size))) end random end |