Module: RubyHome::Password
- Defined in:
- lib/ruby_home/password.rb
Constant Summary collapse
- DELIMITER =
'-'
- LENGTH =
8
- INVALIDS =
[ '00000000', '11111111', '22222222', '33333333', '44444444', '55555555', '66666666', '77777777', '88888888', '99999999', '12345678', '87654321', ]
Class Method Summary collapse
- .format(digits) ⇒ Object
-
.generate ⇒ Object
The Setup Code must conform to the format XXX-XX-XXX where each X is a 0-9 digit and dashes are required.
- .random_digits(length) ⇒ Object
Class Method Details
.format(digits) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ruby_home/password.rb', line 33 def format(digits) [ digits[0...3], digits[3...5], digits[5...8], ].join(DELIMITER) end |
.generate ⇒ Object
The Setup Code must conform to the format XXX-XX-XXX where each X is a 0-9 digit and dashes are required. For example, “101-48-005” (without quotes). The accessory must generate its SRP verifier with the full Setup Code, including dashes.
26 27 28 29 30 31 |
# File 'lib/ruby_home/password.rb', line 26 def generate loop do digits = random_digits(LENGTH) break format(digits.to_s) unless INVALIDS.include?(digits) end end |
.random_digits(length) ⇒ Object
41 42 43 |
# File 'lib/ruby_home/password.rb', line 41 def random_digits(length) Array.new(length) { rand(0..9) }.join end |