Class: Siba::SecurityHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/siba/helpers/security_helper.rb

Class Method Summary collapse

Class Method Details

.alphanumeric_password(length = 16, lowercase_only = false, non_ambiguous = false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/siba/helpers/security_helper.rb', line 16

def alphanumeric_password(length = 16, lowercase_only=false, non_ambiguous = false)
  characters = ('a'..'z').to_a + ('0'..'9').to_a
  characters += ('A'..'Z').to_a unless lowercase_only

  %w{I O l 0 1}.each{ |ambiguous_character|
    characters.delete ambiguous_character
  } if non_ambiguous

  (0...length).map{
    characters[SecureRandom.random_number(characters.size)]
  }.join
end

.generate_password_for_yaml(length = 16) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/siba/helpers/security_helper.rb', line 8

def generate_password_for_yaml(length = 16)
  characters = (32..126).to_a - "\\\"".bytes.to_a - "`".bytes.to_a

  (0...length).map{
    characters[SecureRandom.random_number(characters.size)].chr
  }.join
end