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:
parent
31574751ff
commit
000bc3aaa5
6 changed files with 66 additions and 20 deletions
|
@ -56,13 +56,41 @@ OptionParser.new do |opts|
|
|||
values[:gpg_key] = gpg_key
|
||||
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
|
||||
end
|
||||
|
||||
opts.on('-w', '--wallet-dir PATH', I18n.t('option.wallet_dir')) do |wallet_dir|
|
||||
values[:wallet_dir] = wallet_dir
|
||||
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!
|
||||
|
||||
config = MPW::Config.new(options[:config])
|
||||
|
|
|
@ -56,6 +56,9 @@ en:
|
|||
clipboard: "Disable the clipboard feature"
|
||||
default_wallet: "Specify the default wallet to use"
|
||||
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"
|
||||
file_export: "Specify the file where export data"
|
||||
file_import: "Specify the file to import"
|
||||
|
|
|
@ -56,6 +56,9 @@ fr:
|
|||
clipboard: "Désactive la fonction presse papier"
|
||||
default_wallet: "Spécifie le porte-feuille à utiliser par défaut"
|
||||
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"
|
||||
file_export: "Spécifie le fichier où exporter les données"
|
||||
file_import: "Spécifie le fichier à importer"
|
||||
|
|
|
@ -40,13 +40,7 @@ class Cli
|
|||
# Change a parameter int the config after init
|
||||
# @args: options -> param to change
|
||||
def set_config(options)
|
||||
gpg_key = options[:gpg_key] || @config.key
|
||||
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)
|
||||
@config.setup(options)
|
||||
|
||||
puts "#{I18n.t('form.set_config.valid')}".green
|
||||
rescue Exception => e
|
||||
|
@ -433,7 +427,7 @@ class Cli
|
|||
item = Item.new(options)
|
||||
|
||||
if password
|
||||
options[:password] = MPW::password(length: 24)
|
||||
options[:password] = MPW::password(@config.password)
|
||||
end
|
||||
|
||||
@mpw.add(item)
|
||||
|
|
|
@ -32,6 +32,7 @@ class Config
|
|||
attr_accessor :default_wallet
|
||||
attr_accessor :wallet_dir
|
||||
attr_accessor :gpg_exe
|
||||
attr_accessor :password
|
||||
|
||||
# Constructor
|
||||
# @args: config_file -> the specify config file
|
||||
|
@ -50,23 +51,39 @@ class Config
|
|||
end
|
||||
|
||||
# Create a new config file
|
||||
# @args: key -> the gpg key to encrypt
|
||||
# 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
|
||||
# @args: options -> hash with values
|
||||
# @rtrn: true if le config file is create
|
||||
def setup(key, lang, wallet_dir, default_wallet, gpg_exe)
|
||||
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
|
||||
def setup(options)
|
||||
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')
|
||||
end
|
||||
|
||||
wallet_dir = "#{@config_dir}/wallets" if wallet_dir.to_s.empty?
|
||||
config = { 'key' => key,
|
||||
config = { 'key' => gpg_key,
|
||||
'lang' => lang,
|
||||
'wallet_dir' => wallet_dir,
|
||||
'default_wallet' => default_wallet,
|
||||
'gpg_exe' => gpg_exe,
|
||||
'password' => password,
|
||||
}
|
||||
|
||||
FileUtils.mkdir_p(@config_dir, mode: 0700)
|
||||
|
@ -119,6 +136,7 @@ class Config
|
|||
@wallet_dir = config['wallet_dir']
|
||||
@default_wallet = config['default_wallet']
|
||||
@gpg_exe = config['gpg_exe']
|
||||
@password = config['password']
|
||||
|
||||
raise if @key.empty? or @wallet_dir.empty?
|
||||
|
||||
|
|
|
@ -431,9 +431,9 @@ class MPW
|
|||
end
|
||||
|
||||
chars = []
|
||||
chars += [*('!'..'?')] - [*('0'..'9')] if options.include?(:special)
|
||||
chars += [*('A'..'Z'),*('a'..'z')] if options.include?(:alpha)
|
||||
chars += [*('0'..'9')] if options.include?(:numeric)
|
||||
chars += [*('!'..'?')] - [*('0'..'9')] if options[:special]
|
||||
chars += [*('A'..'Z'),*('a'..'z')] if options[:alpha]
|
||||
chars += [*('0'..'9')] if options[:numeric]
|
||||
chars = [*('A'..'Z'),*('a'..'z'),*('0'..'9')] if chars.empty?
|
||||
|
||||
result = ''
|
||||
|
|
Loading…
Reference in a new issue