mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 07:33:05 +00:00
add generate Password
This commit is contained in:
parent
25f4f7280a
commit
c590c672a1
4 changed files with 26 additions and 6 deletions
|
@ -35,6 +35,7 @@ en:
|
||||||
import: "Import item since a CSV file"
|
import: "Import item since a CSV file"
|
||||||
force: "Force an action"
|
force: "Force an action"
|
||||||
format: "Change the display items format by an alternative format"
|
format: "Change the display items format by an alternative format"
|
||||||
|
generate_password: "Generate a random password (default 8 characters, max 63 characters)"
|
||||||
help: "Show this help message"
|
help: "Show this help message"
|
||||||
form:
|
form:
|
||||||
add:
|
add:
|
||||||
|
|
|
@ -35,6 +35,7 @@ fr:
|
||||||
import: "Importe des éléments depuis un fichier au format CSV"
|
import: "Importe des éléments depuis un fichier au format CSV"
|
||||||
force: "Force une action, l'action ne demandera pas de confirmation"
|
force: "Force une action, l'action ne demandera pas de confirmation"
|
||||||
format: "Change le format d'affichage des éléments par un alternatif"
|
format: "Change le format d'affichage des éléments par un alternatif"
|
||||||
|
generate_password: "Génére un mot de passe aléatoire (défaut 8 caractères, max 63 caractères)"
|
||||||
help: "Affiche ce message d'aide"
|
help: "Affiche ce message d'aide"
|
||||||
form:
|
form:
|
||||||
add:
|
add:
|
||||||
|
|
12
lib/MPW.rb
12
lib/MPW.rb
|
@ -354,4 +354,16 @@ class MPW
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generate a random password
|
||||||
|
# @args: length -> the length password
|
||||||
|
# @rtrn: a random string
|
||||||
|
def self.generatePassword(length=8)
|
||||||
|
if length.to_i <= 0
|
||||||
|
length = 8
|
||||||
|
end
|
||||||
|
|
||||||
|
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(length.to_i).join
|
||||||
|
#return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]-%w(0 1 I O l i o)).sample(length).join
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
18
mpw
18
mpw
|
@ -11,6 +11,7 @@ require 'i18n'
|
||||||
|
|
||||||
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
||||||
require "#{APP_ROOT}/lib/Cli.rb"
|
require "#{APP_ROOT}/lib/Cli.rb"
|
||||||
|
require "#{APP_ROOT}/lib/MPW.rb"
|
||||||
|
|
||||||
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
|
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ OptionParser.new do |opts|
|
||||||
search.nil? ? (options[:display] = '') : (options[:display] = search)
|
search.nil? ? (options[:display] = '') : (options[:display] = search)
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-A', '--show-all', I18n.t('cli.option.show_all')) do |b|
|
opts.on('-A', '--show-all', I18n.t('cli.option.show_all')) do
|
||||||
options[:type] = nil
|
options[:type] = nil
|
||||||
options[:display] = ''
|
options[:display] = ''
|
||||||
end
|
end
|
||||||
|
@ -49,7 +50,7 @@ OptionParser.new do |opts|
|
||||||
options[:group] = group
|
options[:group] = group
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-a', '--add', I18n.t('cli.option.add')) do |b|
|
opts.on('-a', '--add', I18n.t('cli.option.add')) do
|
||||||
options[:add] = true
|
options[:add] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ OptionParser.new do |opts|
|
||||||
options[:config] = config
|
options[:config] = config
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-S', '--setup', I18n.t('cli.option.setup')) do |b|
|
opts.on('-S', '--setup', I18n.t('cli.option.setup')) do
|
||||||
options[:setup] = true
|
options[:setup] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,15 +74,20 @@ OptionParser.new do |opts|
|
||||||
options[:import] = file
|
options[:import] = file
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-f', '--force', I18n.t('cli.option.force')) do |b|
|
opts.on('-f', '--force', I18n.t('cli.option.force')) do
|
||||||
options[:force] = true
|
options[:force] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-F', '--format', I18n.t('cli.option.format')) do |b|
|
opts.on('-F', '--format', I18n.t('cli.option.format')) do
|
||||||
options[:format] = true
|
options[:format] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-h', '--help', I18n.t('cli.option.help')) do |b|
|
opts.on('-G', '--generate-password [LENGTH]', I18n.t('cli.option.generate_password')) do |length|
|
||||||
|
puts MPW::generatePassword(length)
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on('-h', '--help', I18n.t('cli.option.help')) do
|
||||||
puts opts
|
puts opts
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue