Sha256: 8b569eb5dcdd2dcfcafdb73a460dc871a977b34360585776f4d5a34844376a21
Contents?: true
Size: 1.38 KB
Versions: 5
Compression:
Stored size: 1.38 KB
Contents
require 'sym/errors' module Sym module App module Input class Handler attr_accessor :stdin, :stdout, :stderr, :kernel def initialize(stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil) self.stdin = stdin self.stdout = stdout self.stderr = stderr self.kernel = kernel end def ask retries ||= 0 prompt('Password: ', :green) rescue ::OpenSSL::Cipher::CipherError stderr.puts 'Invalid password. Please try again.' retry if (retries += 1) < 3 nil end def puts(*args) stderr.puts args end def prompt(message, color) raise Sym::Errors::CantReadPasswordNoTTY.new('key requires a password, however STDIN is not a TTY') unless stdin.tty? HighLine.new(stdin, stderr).ask(message.bold) { |q| q.echo = '•'.send(color) } end def new_password password = prompt('New Password : ', :blue) raise Sym::Errors::PasswordTooShort.new( 'Minimum length is 7 characters.') if password.length < 7 password_confirm = prompt('Confirm Password : ', :blue) raise Sym::Errors::PasswordsDontMatch.new( 'The passwords you entered do not match.') if password != password_confirm password end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems