mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 13:57:52 +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"
|
||||
force: "Force an action"
|
||||
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"
|
||||
form:
|
||||
add:
|
||||
|
|
|
@ -35,6 +35,7 @@ fr:
|
|||
import: "Importe des éléments depuis un fichier au format CSV"
|
||||
force: "Force une action, l'action ne demandera pas de confirmation"
|
||||
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"
|
||||
form:
|
||||
add:
|
||||
|
|
12
lib/MPW.rb
12
lib/MPW.rb
|
@ -354,4 +354,16 @@ class MPW
|
|||
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
|
||||
|
|
18
mpw
18
mpw
|
@ -11,6 +11,7 @@ require 'i18n'
|
|||
|
||||
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
||||
require "#{APP_ROOT}/lib/Cli.rb"
|
||||
require "#{APP_ROOT}/lib/MPW.rb"
|
||||
|
||||
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)
|
||||
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[:display] = ''
|
||||
end
|
||||
|
@ -49,7 +50,7 @@ OptionParser.new do |opts|
|
|||
options[:group] = group
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -57,7 +58,7 @@ OptionParser.new do |opts|
|
|||
options[:config] = config
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -73,15 +74,20 @@ OptionParser.new do |opts|
|
|||
options[:import] = file
|
||||
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
|
||||
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
|
||||
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
|
||||
exit 0
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue