1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 02:33:19 +00:00
This commit is contained in:
Adrien Waksberg 2017-03-29 22:50:47 +02:00
parent e71f8e2acf
commit 8ed90c2ddc
5 changed files with 16 additions and 16 deletions

View file

@ -72,9 +72,9 @@ else
cli.get_wallet(options[:wallet])
cli.decrypt
if not options[:list_keys].nil?
if !options[:list_keys].nil?
cli.list_keys
elsif not options[:gpg_key].nil?
elsif !options[:gpg_key].nil?
if options[:delete]
cli.delete_key(options[:gpg_key])
else

View file

@ -155,7 +155,7 @@ class Cli
items.each do |item|
data.each do |k, v|
next if k == :id or k == :otp
next if k == :id || k == :otp
v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length]
end
@ -240,7 +240,7 @@ class Cli
items.sort! { |a,b| a.group.to_s.downcase <=> b.group.to_s.downcase }
choice = ask(I18n.t('form.select')).to_i
if choice >= 1 and choice <= items.length
if choice >= 1 && choice <= items.length
return items[choice-1]
else
return nil
@ -331,7 +331,7 @@ class Cli
if wallets.length == 1
@wallet_file = wallets[0]
elsif not @config.default_wallet.to_s.empty?
elsif !@config.default_wallet.to_s.empty?
@wallet_file = "#{@config.wallet_dir}/#{@config.default_wallet}.mpw"
else
@wallet_file = "#{@config.wallet_dir}/default.mpw"

View file

@ -47,7 +47,7 @@ class Config
@config_dir = "#{Dir.home}/.config/mpw"
end
@config_file = "#{@config_dir}/mpw.cfg" if @config_file.nil? or @config_file.empty?
@config_file = "#{@config_dir}/mpw.cfg" if @config_file.nil? || @config_file.empty?
end
# Create a new config file
@ -68,7 +68,7 @@ class Config
['numeric', 'special', 'alpha', 'length'].each do |k|
if options.has_key?("pwd_#{k}".to_sym)
password[k.to_sym] = options["pwd_#{k}".to_sym]
elsif not @password.nil? and @password.has_key?(k.to_sym)
elsif !@password.nil? && @password.has_key?(k.to_sym)
password[k.to_sym] = @password[k.to_sym]
end
end
@ -138,7 +138,7 @@ class Config
@gpg_exe = config['gpg_exe']
@password = config['password'] || {}
raise if @gpg_key.empty? or @wallet_dir.empty?
raise if @gpg_key.empty? || @wallet_dir.empty?
I18n.locale = @lang.to_sym
rescue Exception => e

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 not options.has_key?(:host) or options[:host].to_s.empty?
if !options.has_key?(:host) || options[:host].to_s.empty?
raise I18n.t('error.update.host_empty')
end
if not options.has_key?(:id) or options[:id].to_s.empty? or not options.has_key?(:created) or options[:created].to_s.empty?
if !options.has_key?(:id) || options[:id].to_s.empty? || !options.has_key?(:created) || options[:created].to_s.empty?
@id = generate_id
@created = Time.now.to_i
else
@ -57,7 +57,7 @@ class Item
# Update the item
# @args: options -> a hash of parameter
def update(options={})
if options.has_key?(:host) and options[:host].to_s.empty?
if options.has_key?(:host) && options[:host].to_s.empty?
raise I18n.t('error.update.host_empty')
end
@ -65,7 +65,7 @@ class Item
@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) and not options[:port].to_s.empty?
@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)

View file

@ -237,7 +237,7 @@ class MPW
raise I18n.t('error.bad_class') unless item.instance_of?(Item)
raise I18n.t('error.empty') if item.empty?
return @data.push(item)
@data.push(item)
end
# Search in some csv data
@ -251,12 +251,12 @@ class MPW
@data.each do |item|
next if item.empty?
next unless group.empty? or group.eql?(item.group.to_s.downcase)
next unless group.empty? || group.eql?(item.group.to_s.downcase)
host = item.host.to_s.downcase
comment = item.comment.to_s.downcase
next unless host =~ /^.*#{search}.*$/ or comment =~ /^.*#{search}.*$/
next unless host =~ /^.*#{search}.*$/ || comment =~ /^.*#{search}.*$/
result.push(item)
end
@ -315,7 +315,7 @@ class MPW
# @args: options -> :length, :special, :alpha, :numeric
# @rtrn: a random string
def self.password(options={})
if not options.include?(:length) or options[:length].to_i <= 0
if !options.include?(:length) || options[:length].to_i <= 0
length = 8
elsif options[:length].to_i >= 32768
length = 32768