mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-21 10:20:05 +00:00
replace hash method has_key? by key?
This commit is contained in:
parent
e7fff4bb87
commit
31aba3b13c
5 changed files with 27 additions and 27 deletions
|
@ -96,7 +96,7 @@ end.parse!
|
||||||
config = MPW::Config.new(options[:config])
|
config = MPW::Config.new(options[:config])
|
||||||
cli = MPW::Cli.new(config, nil)
|
cli = MPW::Cli.new(config, nil)
|
||||||
|
|
||||||
if options.has_key?(:init)
|
if options.key?(:init)
|
||||||
cli.setup(values)
|
cli.setup(values)
|
||||||
cli.load_config
|
cli.load_config
|
||||||
cli.get_wallet
|
cli.get_wallet
|
||||||
|
|
|
@ -399,8 +399,8 @@ class Cli
|
||||||
options[:password] = MPW::password(@config.password) if password
|
options[:password] = MPW::password(@config.password) if password
|
||||||
|
|
||||||
@mpw.add(item)
|
@mpw.add(item)
|
||||||
@mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
|
@mpw.set_password(item.id, options[:password]) if options.key?(:password)
|
||||||
@mpw.set_otp_key(item.id, options[:otp_key]) if options.has_key?(:otp_key)
|
@mpw.set_otp_key(item.id, options[:otp_key]) if options.key?(:otp_key)
|
||||||
@mpw.write_data
|
@mpw.write_data
|
||||||
|
|
||||||
puts "#{I18n.t('form.add_item.valid')}".green
|
puts "#{I18n.t('form.add_item.valid')}".green
|
||||||
|
@ -424,8 +424,8 @@ class Cli
|
||||||
options[:password] = MPW::password(@config.password) if password
|
options[:password] = MPW::password(@config.password) if password
|
||||||
|
|
||||||
item.update(options)
|
item.update(options)
|
||||||
@mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
|
@mpw.set_password(item.id, options[:password]) if options.key?(:password)
|
||||||
@mpw.set_otp_key(item.id, options[:otp_key]) if options.has_key?(:otp_key)
|
@mpw.set_otp_key(item.id, options[:otp_key]) if options.key?(:otp_key)
|
||||||
@mpw.write_data
|
@mpw.write_data
|
||||||
|
|
||||||
puts "#{I18n.t('form.update_item.valid')}".green
|
puts "#{I18n.t('form.update_item.valid')}".green
|
||||||
|
|
|
@ -66,9 +66,9 @@ class Config
|
||||||
}
|
}
|
||||||
|
|
||||||
['numeric', 'special', 'alpha', 'length'].each do |k|
|
['numeric', 'special', 'alpha', 'length'].each do |k|
|
||||||
if options.has_key?("pwd_#{k}".to_sym)
|
if options.key?("pwd_#{k}".to_sym)
|
||||||
password[k.to_sym] = options["pwd_#{k}".to_sym]
|
password[k.to_sym] = options["pwd_#{k}".to_sym]
|
||||||
elsif !@password.nil? && @password.has_key?(k.to_sym)
|
elsif !@password.nil? && @password.key?(k.to_sym)
|
||||||
password[k.to_sym] = @password[k.to_sym]
|
password[k.to_sym] = @password[k.to_sym]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,11 +37,11 @@ class Item
|
||||||
# @args: options -> a hash of parameter
|
# @args: options -> a hash of parameter
|
||||||
# raise an error if the hash hasn't the key name
|
# raise an error if the hash hasn't the key name
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
if !options.has_key?(:host) || options[:host].to_s.empty?
|
if !options.key?(:host) || options[:host].to_s.empty?
|
||||||
raise I18n.t('error.update.host_empty')
|
raise I18n.t('error.update.host_empty')
|
||||||
end
|
end
|
||||||
|
|
||||||
if !options.has_key?(:id) || options[:id].to_s.empty? || !options.has_key?(:created) || options[:created].to_s.empty?
|
if !options.key?(:id) || options[:id].to_s.empty? || !options.key?(:created) || options[:created].to_s.empty?
|
||||||
@id = generate_id
|
@id = generate_id
|
||||||
@created = Time.now.to_i
|
@created = Time.now.to_i
|
||||||
else
|
else
|
||||||
|
@ -57,18 +57,18 @@ class Item
|
||||||
# Update the item
|
# Update the item
|
||||||
# @args: options -> a hash of parameter
|
# @args: options -> a hash of parameter
|
||||||
def update(options={})
|
def update(options={})
|
||||||
if options.has_key?(:host) && options[:host].to_s.empty?
|
if options.key?(:host) && options[:host].to_s.empty?
|
||||||
raise I18n.t('error.update.host_empty')
|
raise I18n.t('error.update.host_empty')
|
||||||
end
|
end
|
||||||
|
|
||||||
@group = options[:group] if options.has_key?(:group)
|
@group = options[:group] if options.key?(:group)
|
||||||
@host = options[:host] if options.has_key?(:host)
|
@host = options[:host] if options.key?(:host)
|
||||||
@protocol = options[:protocol] if options.has_key?(:protocol)
|
@protocol = options[:protocol] if options.key?(:protocol)
|
||||||
@user = options[:user] if options.has_key?(:user)
|
@user = options[:user] if options.key?(:user)
|
||||||
@port = options[:port].to_i if options.has_key?(:port) && !options[:port].to_s.empty?
|
@port = options[:port].to_i if options.key?(:port) && !options[:port].to_s.empty?
|
||||||
@otp = options[:otp] if options.has_key?(:otp)
|
@otp = options[:otp] if options.key?(:otp)
|
||||||
@comment = options[:comment] if options.has_key?(:comment)
|
@comment = options[:comment] if options.key?(:comment)
|
||||||
@last_edit = Time.now.to_i unless options.has_key?(:no_update_last_edit)
|
@last_edit = Time.now.to_i unless options.key?(:no_update_last_edit)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delete all data
|
# Delete all data
|
||||||
|
|
|
@ -88,7 +88,7 @@ class MPW
|
||||||
protocol: d['protocol'],
|
protocol: d['protocol'],
|
||||||
user: d['user'],
|
user: d['user'],
|
||||||
port: d['port'],
|
port: d['port'],
|
||||||
otp: @otp_keys.has_key?(d['id']),
|
otp: @otp_keys.key?(d['id']),
|
||||||
comment: d['comment'],
|
comment: d['comment'],
|
||||||
last_edit: d['last_edit'],
|
last_edit: d['last_edit'],
|
||||||
created: d['created'],
|
created: d['created'],
|
||||||
|
@ -223,12 +223,12 @@ class MPW
|
||||||
def set_config(options={})
|
def set_config(options={})
|
||||||
@config = {} if @config.nil?
|
@config = {} if @config.nil?
|
||||||
|
|
||||||
@config['protocol'] = options[:protocol] if options.has_key?(:protocol)
|
@config['protocol'] = options[:protocol] if options.key?(:protocol)
|
||||||
@config['host'] = options[:host] if options.has_key?(:host)
|
@config['host'] = options[:host] if options.key?(:host)
|
||||||
@config['port'] = options[:port] if options.has_key?(:port)
|
@config['port'] = options[:port] if options.key?(:port)
|
||||||
@config['user'] = options[:user] if options.has_key?(:user)
|
@config['user'] = options[:user] if options.key?(:user)
|
||||||
@config['password'] = options[:password] if options.has_key?(:password)
|
@config['password'] = options[:password] if options.key?(:password)
|
||||||
@config['path'] = options[:path] if options.has_key?(:path)
|
@config['path'] = options[:path] if options.key?(:path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a new item
|
# Add a new item
|
||||||
|
@ -286,14 +286,14 @@ class MPW
|
||||||
# args: id -> the item id
|
# args: id -> the item id
|
||||||
# key -> the new key
|
# key -> the new key
|
||||||
def get_otp_key(id)
|
def get_otp_key(id)
|
||||||
@otp_keys.has_key?(id) ? decrypt(@otp_keys[id]) : nil
|
@otp_keys.key?(id) ? decrypt(@otp_keys[id]) : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get an otp code
|
# Get an otp code
|
||||||
# @args: id -> the item id
|
# @args: id -> the item id
|
||||||
# @rtrn: an otp code
|
# @rtrn: an otp code
|
||||||
def get_otp_code(id)
|
def get_otp_code(id)
|
||||||
@otp_keys.has_key?(id) ? 0 : ROTP::TOTP.new(decrypt(@otp_keys[id])).now
|
@otp_keys.key?(id) ? 0 : ROTP::TOTP.new(decrypt(@otp_keys[id])).now
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get remaining time before expire otp code
|
# Get remaining time before expire otp code
|
||||||
|
|
Loading…
Add table
Reference in a new issue