Class: Secrets::App::PasswordHandler
- Inherits:
-
Object
- Object
- Secrets::App::PasswordHandler
- Defined in:
- lib/secrets/app/password_handler.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#password ⇒ Object
Returns the value of attribute password.
Class Method Summary collapse
Instance Method Summary collapse
- #ask ⇒ Object
- #create ⇒ Object
-
#initialize(opts) ⇒ PasswordHandler
constructor
A new instance of PasswordHandler.
Constructor Details
#initialize(opts) ⇒ PasswordHandler
Returns a new instance of PasswordHandler.
8 9 10 |
# File 'lib/secrets/app/password_handler.rb', line 8 def initialize(opts) self.opts = opts end |
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
6 7 8 |
# File 'lib/secrets/app/password_handler.rb', line 6 def opts @opts end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/secrets/app/password_handler.rb', line 6 def password @password end |
Class Method Details
.handle_user_input(message, color) ⇒ Object
20 21 22 |
# File 'lib/secrets/app/password_handler.rb', line 20 def self.handle_user_input(, color) HighLine.new(STDIN, STDERR).ask(.bold) { |q| q.echo = '•'.send(color) } end |
Instance Method Details
#ask ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/secrets/app/password_handler.rb', line 12 def ask retries ||= 0 self.password = self.class.handle_user_input('Password: ', :green) rescue ::OpenSSL::Cipher::CipherError STDERR.puts 'Invalid password. Please try again.' retry if (retries += 1) < 3 end |
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/secrets/app/password_handler.rb', line 24 def create if opts[:password] self.password = self.class.handle_user_input('New Password : ', :blue) password_confirm = self.class.handle_user_input('Confirm Password : ', :blue) raise Secrets::Errors::PasswordsDontMatch.new( 'The passwords you entered do not match.') if password != password_confirm raise Secrets::Errors::PasswordTooShort.new( 'Minimum length is 7 characters.') if password.length < 7 end self end |