Sha256: 0a5c2ada4dae8ac461a5a4e1a3c8171c1548549d4d7db6d7df7fcca9a8656f26
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
require 'md5' module Capitate::Plugins::Prompt # Prompt. # # ==== Options # +label+:: Label # +options+:: Options (none yet) # def ask(label, options = {}, &block) Capistrano::CLI.ui.ask(label, &block) end # Prompt for password. # # ==== Options # +label+:: Label # +options+:: Options # - +verify+:: If true, prompt twice and verify # - +lazy+:: If true, returns a Proc. _Defaults to true_ # - +check_hash+:: If present, checks that md5 is same as password md5 # def password(label, options = {}) verify = options[:verify] lazy = options[:lazy].nil? ? true : options[:lazy] check_hash = options[:check_hash] # Lazy password_prompt = Proc.new { max_attempts = 2 attempts = 0 password = nil success = true loop { password = Capistrano::CLI.password_prompt(label) attempts += 1 if verify password_verify = Capistrano::CLI.password_prompt("[VERIFY] #{label}") if password != password_verify logger.important "Passwords do not match" success = false end end if check_hash if MD5.md5(password).hexdigest != check_hash logger.important "Invalid password, try again." success = false end end break if success break if attempts >= max_attempts } raise "Invalid password, too many tries" unless success password } return password_prompt if lazy password_prompt.call end def check_password_hash(password, hash) MD5.md5() end end Capistrano.plugin :prompt, Capitate::Plugins::Prompt
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
capitate-0.2.11 | lib/capitate/plugins/prompt.rb |