module PasswordMate

Constants

LowercaseLetters
Numbers
PasswordLength
SpecialCharacters
UppercaseLetters

Public Instance Methods

generate_random_password() click to toggle source
# File lib/password_mate.rb, line 19
def generate_random_password
  password = generate_random(PasswordLength) until strong?(password)
  password
end
strong?(str) click to toggle source
# File lib/password_mate.rb, line 10
def strong?(str)
  return false if str && str.empty?
  return false unless str =~ Regexp.union(*SpecialCharacters)
  return false unless str =~ Regexp.union(*LowercaseLetters)
  return false unless str =~ Regexp.union(*UppercaseLetters)
  return false unless str =~ Regexp.union(*Numbers)
  true
end

Private Instance Methods

all_possible_characters() click to toggle source
# File lib/password_mate.rb, line 35
def all_possible_characters
  SpecialCharacters + LowercaseLetters +
  UppercaseLetters + Numbers
end
generate_random(length) click to toggle source
# File lib/password_mate.rb, line 25
def generate_random(length)
  "".tap do |str|
    length.times { str << random_character }
  end
end
random_character() click to toggle source
# File lib/password_mate.rb, line 31
def random_character
  all_possible_characters.sample
end