1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 05:47:53 +00:00

add config option for password parameters

This commit is contained in:
Adrien Waksberg 2017-02-25 18:43:30 +01:00
parent 31574751ff
commit 000bc3aaa5
6 changed files with 66 additions and 20 deletions

View file

@ -56,13 +56,41 @@ OptionParser.new do |opts|
values[:gpg_key] = gpg_key values[:gpg_key] = gpg_key
end end
opts.on('-l', '--lang LANG', I18n.t('option.lang')) do |lang| opts.on('-L', '--lang LANG', I18n.t('option.lang')) do |lang|
values[:lang] = lang values[:lang] = lang
end end
opts.on('-w', '--wallet-dir PATH', I18n.t('option.wallet_dir')) do |wallet_dir| opts.on('-w', '--wallet-dir PATH', I18n.t('option.wallet_dir')) do |wallet_dir|
values[:wallet_dir] = wallet_dir values[:wallet_dir] = wallet_dir
end end
opts.on('-l', '--length NUMBER', I18n.t('option.length')) do |length|
values[:pwd_length] = length.to_i
end
opts.on('-n', '--numeric', I18n.t('option.numeric')) do
values[:pwd_numeric] = true
end
opts.on('-N', '--disable-numeric', I18n.t('option.disable_numeric')) do
values[:pwd_numeric] = false
end
opts.on('-s', '--special-chars', I18n.t('option.special_chars')) do
values[:pwd_special] = true
end
opts.on('-S', '--disable_special-chars', I18n.t('option.special_chars')) do
values[:pwd_special] = false
end
opts.on('-a', '--alpha', I18n.t('option.alpha')) do
values[:pwd_alpha] = true
end
opts.on('-A', '--disable-alpha', I18n.t('option.disable_alpha')) do
values[:pwd_alpha] = false
end
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])

View file

@ -56,6 +56,9 @@ en:
clipboard: "Disable the clipboard feature" clipboard: "Disable the clipboard feature"
default_wallet: "Specify the default wallet to use" default_wallet: "Specify the default wallet to use"
delete_gpg_key: "Delete the wallet's share with an other GPG key" delete_gpg_key: "Delete the wallet's share with an other GPG key"
disable_alpha: "Don't use letter to generate a password"
disable_numeric: "Don't use number to generate a password"
disable_special_chars: "Don't use special char to generate a password"
export: "Export a wallet in an yaml file" export: "Export a wallet in an yaml file"
file_export: "Specify the file where export data" file_export: "Specify the file where export data"
file_import: "Specify the file to import" file_import: "Specify the file to import"

View file

@ -56,6 +56,9 @@ fr:
clipboard: "Désactive la fonction presse papier" clipboard: "Désactive la fonction presse papier"
default_wallet: "Spécifie le porte-feuille à utiliser par défaut" default_wallet: "Spécifie le porte-feuille à utiliser par défaut"
delete_gpg_key: "Supprime le partage le portefeuille avec une autre clé GPG" delete_gpg_key: "Supprime le partage le portefeuille avec une autre clé GPG"
disable_alpha: "Désactive l'utilisation des lettres dans la génération d'un mot de passe"
disable_numeric: "Désactive l'utilisation des chiffre dans la génération d'un mot de passe"
disable_special_chars: "Désactive l'utilisation des charactères speciaux dans la génération d'un mot de passe"
export: "Exporte un portefeuille dans un fichier yaml" export: "Exporte un portefeuille dans un fichier yaml"
file_export: "Spécifie le fichier où exporter les données" file_export: "Spécifie le fichier où exporter les données"
file_import: "Spécifie le fichier à importer" file_import: "Spécifie le fichier à importer"

View file

@ -40,13 +40,7 @@ class Cli
# Change a parameter int the config after init # Change a parameter int the config after init
# @args: options -> param to change # @args: options -> param to change
def set_config(options) def set_config(options)
gpg_key = options[:gpg_key] || @config.key @config.setup(options)
lang = options[:lang] || @config.lang
wallet_dir = options[:wallet_dir] || @config.wallet_dir
default_wallet = options[:default_wallet] || @config.default_wallet
gpg_exe = options[:gpg_exe] || @config.gpg_exe
@config.setup(gpg_key, lang, wallet_dir, default_wallet, gpg_exe)
puts "#{I18n.t('form.set_config.valid')}".green puts "#{I18n.t('form.set_config.valid')}".green
rescue Exception => e rescue Exception => e
@ -433,7 +427,7 @@ class Cli
item = Item.new(options) item = Item.new(options)
if password if password
options[:password] = MPW::password(length: 24) options[:password] = MPW::password(@config.password)
end end
@mpw.add(item) @mpw.add(item)

View file

@ -32,6 +32,7 @@ class Config
attr_accessor :default_wallet attr_accessor :default_wallet
attr_accessor :wallet_dir attr_accessor :wallet_dir
attr_accessor :gpg_exe attr_accessor :gpg_exe
attr_accessor :password
# Constructor # Constructor
# @args: config_file -> the specify config file # @args: config_file -> the specify config file
@ -50,23 +51,39 @@ class Config
end end
# Create a new config file # Create a new config file
# @args: key -> the gpg key to encrypt # @args: options -> hash with values
# lang -> the software language
# wallet_dir -> the directory where are the wallets password
# default_wallet -> the default wallet
# gpg_exe -> the path of gpg executable
# @rtrn: true if le config file is create # @rtrn: true if le config file is create
def setup(key, lang, wallet_dir, default_wallet, gpg_exe) def setup(options)
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/ gpg_key = options[:gpg_key] || @key
lang = options[:lang] || @lang
wallet_dir = options[:wallet_dir] || @wallet_dir
default_wallet = options[:default_wallet] || @default_wallet
gpg_exe = options[:gpg_exe] || @gpg_exe
password = { numeric: true,
alpha: true,
special: false,
length: 16,
}
['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)
password[k.to_sym] = @password[k.to_sym]
end
end
if not gpg_key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
raise I18n.t('error.config.key_bad_format') raise I18n.t('error.config.key_bad_format')
end end
wallet_dir = "#{@config_dir}/wallets" if wallet_dir.to_s.empty? wallet_dir = "#{@config_dir}/wallets" if wallet_dir.to_s.empty?
config = { 'key' => key, config = { 'key' => gpg_key,
'lang' => lang, 'lang' => lang,
'wallet_dir' => wallet_dir, 'wallet_dir' => wallet_dir,
'default_wallet' => default_wallet, 'default_wallet' => default_wallet,
'gpg_exe' => gpg_exe, 'gpg_exe' => gpg_exe,
'password' => password,
} }
FileUtils.mkdir_p(@config_dir, mode: 0700) FileUtils.mkdir_p(@config_dir, mode: 0700)
@ -119,6 +136,7 @@ class Config
@wallet_dir = config['wallet_dir'] @wallet_dir = config['wallet_dir']
@default_wallet = config['default_wallet'] @default_wallet = config['default_wallet']
@gpg_exe = config['gpg_exe'] @gpg_exe = config['gpg_exe']
@password = config['password']
raise if @key.empty? or @wallet_dir.empty? raise if @key.empty? or @wallet_dir.empty?

View file

@ -431,9 +431,9 @@ class MPW
end end
chars = [] chars = []
chars += [*('!'..'?')] - [*('0'..'9')] if options.include?(:special) chars += [*('!'..'?')] - [*('0'..'9')] if options[:special]
chars += [*('A'..'Z'),*('a'..'z')] if options.include?(:alpha) chars += [*('A'..'Z'),*('a'..'z')] if options[:alpha]
chars += [*('0'..'9')] if options.include?(:numeric) chars += [*('0'..'9')] if options[:numeric]
chars = [*('A'..'Z'),*('a'..'z'),*('0'..'9')] if chars.empty? chars = [*('A'..'Z'),*('a'..'z'),*('0'..'9')] if chars.empty?
result = '' result = ''