1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-20 01:50:04 +00:00

replace hash method has_key? by key?

This commit is contained in:
Adrien Waksberg 2017-03-28 22:22:09 +02:00
parent e7fff4bb87
commit 31aba3b13c
5 changed files with 27 additions and 27 deletions

View file

@ -96,7 +96,7 @@ end.parse!
config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config, nil)
if options.has_key?(:init)
if options.key?(:init)
cli.setup(values)
cli.load_config
cli.get_wallet

View file

@ -399,8 +399,8 @@ class Cli
options[:password] = MPW::password(@config.password) if password
@mpw.add(item)
@mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
@mpw.set_otp_key(item.id, options[:otp_key]) if options.has_key?(:otp_key)
@mpw.set_password(item.id, options[:password]) if options.key?(:password)
@mpw.set_otp_key(item.id, options[:otp_key]) if options.key?(:otp_key)
@mpw.write_data
puts "#{I18n.t('form.add_item.valid')}".green
@ -424,8 +424,8 @@ class Cli
options[:password] = MPW::password(@config.password) if password
item.update(options)
@mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
@mpw.set_otp_key(item.id, options[:otp_key]) if options.has_key?(:otp_key)
@mpw.set_password(item.id, options[:password]) if options.key?(:password)
@mpw.set_otp_key(item.id, options[:otp_key]) if options.key?(:otp_key)
@mpw.write_data
puts "#{I18n.t('form.update_item.valid')}".green

View file

@ -66,9 +66,9 @@ class Config
}
['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]
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]
end
end

View file

@ -37,11 +37,11 @@ class Item
# @args: options -> a hash of parameter
# raise an error if the hash hasn't the key name
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')
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
@created = Time.now.to_i
else
@ -57,18 +57,18 @@ class Item
# Update the item
# @args: options -> a hash of parameter
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')
end
@group = options[:group] if options.has_key?(:group)
@host = options[:host] if options.has_key?(:host)
@protocol = options[:protocol] if options.has_key?(:protocol)
@user = options[:user] if options.has_key?(:user)
@port = options[:port].to_i if options.has_key?(:port) && !options[:port].to_s.empty?
@otp = options[:otp] if options.has_key?(:otp)
@comment = options[:comment] if options.has_key?(:comment)
@last_edit = Time.now.to_i unless options.has_key?(:no_update_last_edit)
@group = options[:group] if options.key?(:group)
@host = options[:host] if options.key?(:host)
@protocol = options[:protocol] if options.key?(:protocol)
@user = options[:user] if options.key?(:user)
@port = options[:port].to_i if options.key?(:port) && !options[:port].to_s.empty?
@otp = options[:otp] if options.key?(:otp)
@comment = options[:comment] if options.key?(:comment)
@last_edit = Time.now.to_i unless options.key?(:no_update_last_edit)
end
# Delete all data

View file

@ -88,7 +88,7 @@ class MPW
protocol: d['protocol'],
user: d['user'],
port: d['port'],
otp: @otp_keys.has_key?(d['id']),
otp: @otp_keys.key?(d['id']),
comment: d['comment'],
last_edit: d['last_edit'],
created: d['created'],
@ -223,12 +223,12 @@ class MPW
def set_config(options={})
@config = {} if @config.nil?
@config['protocol'] = options[:protocol] if options.has_key?(:protocol)
@config['host'] = options[:host] if options.has_key?(:host)
@config['port'] = options[:port] if options.has_key?(:port)
@config['user'] = options[:user] if options.has_key?(:user)
@config['password'] = options[:password] if options.has_key?(:password)
@config['path'] = options[:path] if options.has_key?(:path)
@config['protocol'] = options[:protocol] if options.key?(:protocol)
@config['host'] = options[:host] if options.key?(:host)
@config['port'] = options[:port] if options.key?(:port)
@config['user'] = options[:user] if options.key?(:user)
@config['password'] = options[:password] if options.key?(:password)
@config['path'] = options[:path] if options.key?(:path)
end
# Add a new item
@ -286,14 +286,14 @@ class MPW
# args: id -> the item id
# key -> the new key
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
# Get an otp code
# @args: id -> the item id
# @rtrn: an otp code
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
# Get remaining time before expire otp code