Sha256: f0942c51f69a215bf417fe00c2814add306faec1e4d13b0e8909fad22c96a5af

Contents?: true

Size: 1012 Bytes

Versions: 17

Compression:

Stored size: 1012 Bytes

Contents

require 'sym/errors'

module Sym
  module App
    module Input
      class Handler

        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)
          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

17 entries across 17 versions & 1 rubygems

Version Path
sym-2.6.2 lib/sym/app/input/handler.rb
sym-2.6.1 lib/sym/app/input/handler.rb
sym-2.6.0 lib/sym/app/input/handler.rb
sym-2.5.3 lib/sym/app/input/handler.rb
sym-2.5.1 lib/sym/app/input/handler.rb
sym-2.5.0 lib/sym/app/input/handler.rb
sym-2.4.3 lib/sym/app/input/handler.rb
sym-2.3.0 lib/sym/app/input/handler.rb
sym-2.2.1 lib/sym/app/input/handler.rb
sym-2.2.0 lib/sym/app/input/handler.rb
sym-2.1.2 lib/sym/app/input/handler.rb
sym-2.1.1 lib/sym/app/input/handler.rb
sym-2.1.0 lib/sym/app/input/handler.rb
sym-2.0.3 lib/sym/app/input/handler.rb
sym-2.0.2 lib/sym/app/input/handler.rb
sym-2.0.1 lib/sym/app/input/handler.rb
sym-2.0.0 lib/sym/app/input/handler.rb