module Genpasswd
Constants
- VERSION
Public Instance Methods
generate_set(length = 6)
click to toggle source
generate 6 character set
# File lib/genpasswd.rb, line 7 def generate_set(length = 6) ('a'..'z').to_a.shuffle[0, length].join end
insert_capital(string, count = 1)
click to toggle source
insert capital letter
# File lib/genpasswd.rb, line 12 def insert_capital(string, count = 1) arr = [] str = string.downcase while arr.length < count r = rand(str.size - 1) if !!str[r].match(/^(\d)+$/) else arr << r arr.uniq! end end arr.each do |i| str[i] = str[i].upcase end return str end
insert_number(string, count = 1)
click to toggle source
use BEFORE :insert_capital
# File lib/genpasswd.rb, line 30 def insert_number(string, count = 1) arr = [] str = string.downcase while arr.length < count arr << rand(str.size - 1) arr.uniq! end arr.each do |i| str[i] = rand(9).to_s end return str end
make()
click to toggle source
TODO: add parameters
# File lib/genpasswd.rb, line 49 def make password = '' 3.times do password += generate_set(6) end password = insert_number(password) password = insert_capital(password) return prepare(password) end
prepare(str, count = 6)
click to toggle source
# File lib/genpasswd.rb, line 43 def prepare(str, count = 6) arr = str.chars.each_slice(count).map(&:join) arr.join('-') end