Class: Password

Inherits:
Object
  • Object
show all
Defined in:
lib/readable_password_generator.rb

Constant Summary collapse

DEFAULT_PW_LENGTH =

minimum default length is set to 10 by security concerns of a readable password

[10,11,12,13,14,15,16,17,18]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_pw_length = DEFAULT_PW_LENGTH.sample) ⇒ Password

Returns a new instance of Password.



8
9
10
11
# File 'lib/readable_password_generator.rb', line 8

def initialize(a_pw_length = DEFAULT_PW_LENGTH.sample)
  @pw_length = check_length_value(a_pw_length) #checking on password length value
  @vowel_pos = 0 # by default start password with a vowel
end

Instance Attribute Details

#pw_lengthObject (readonly)

Returns the value of attribute pw_length.



6
7
8
# File 'lib/readable_password_generator.rb', line 6

def pw_length
  @pw_length
end

Instance Method Details

#gener_passwObject

generate password of a required length



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/readable_password_generator.rb', line 14

def gener_passw
  #set position for a vowel: either to start a password with it first or not:
  # 0 - start password with a vowel
  # 1 - start password with a consonat(s)
  @vowel_pos = [1, 2].sample
  size, result = @pw_length, ""
  count = 0
  size.times do |char|
    count = 0 if count==2
    count+=1
    result << take_char(count)
  end
  return result = result[0...size]
end

#set_length(a_pw_length) ⇒ Object



29
30
31
32
# File 'lib/readable_password_generator.rb', line 29

def set_length(a_pw_length)
  @pw_length = check_length_value(a_pw_length)
  return nil
end