Sha256: 6e9a991a4ae1434bde3f28b86f4fdbf4c09b103c4841347224664c41e9e810ef

Contents?: true

Size: 1021 Bytes

Versions: 5

Compression:

Stored size: 1021 Bytes

Contents

require 'shhh/errors'

module Shhh
  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 Shhh::Errors::PasswordTooShort.new(
            'Minimum length is 7 characters.') if password.length < 7

          password_confirm = prompt('Confirm Password :  ', :blue)

          raise Shhh::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

Version Path
shhh-1.6.5 lib/shhh/app/input/handler.rb
shhh-1.6.4 lib/shhh/app/input/handler.rb
shhh-1.6.3 lib/shhh/app/input/handler.rb
shhh-1.6.2 lib/shhh/app/input/handler.rb
shhh-1.6.1 lib/shhh/app/input/handler.rb