mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-22 02:40:04 +00:00
add random password when create new item
This commit is contained in:
parent
2e32b223b0
commit
580c5b4193
3 changed files with 19 additions and 6 deletions
|
@ -38,6 +38,10 @@ OptionParser.new do |opts|
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on('-r', '--random', I18n.t('option.random_password')) do
|
||||||
|
options[:password] = true
|
||||||
|
end
|
||||||
|
|
||||||
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
|
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
|
||||||
options[:wallet] = wallet
|
options[:wallet] = wallet
|
||||||
end
|
end
|
||||||
|
@ -48,4 +52,4 @@ cli = MPW::Cli.new(config, options[:sync])
|
||||||
|
|
||||||
cli.get_wallet(options[:wallet])
|
cli.get_wallet(options[:wallet])
|
||||||
cli.decrypt
|
cli.decrypt
|
||||||
cli.add
|
cli.add(options[:password])
|
||||||
|
|
|
@ -368,7 +368,11 @@ class Cli
|
||||||
puts "#{I18n.t('display.error')} #15: #{e}".red
|
puts "#{I18n.t('display.error')} #15: #{e}".red
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_editor(template_name, item=nil)
|
# Text editor interface
|
||||||
|
# @args: template -> template name
|
||||||
|
# item -> the item to edit
|
||||||
|
# password -> disable field password
|
||||||
|
def text_editor(template_name, item=nil, password=false)
|
||||||
editor = ENV['EDITOR'] || 'nano'
|
editor = ENV['EDITOR'] || 'nano'
|
||||||
options = {}
|
options = {}
|
||||||
opts = {}
|
opts = {}
|
||||||
|
@ -397,10 +401,15 @@ class Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
# Form to add a new item
|
# Form to add a new item
|
||||||
def add
|
# @args: password -> generate a random password
|
||||||
options = text_editor('add_form')
|
def add(password=false)
|
||||||
|
options = text_editor('add_form', nil, password)
|
||||||
item = Item.new(options)
|
item = Item.new(options)
|
||||||
|
|
||||||
|
if password
|
||||||
|
options[:password] = MPW::password(length: 24)
|
||||||
|
end
|
||||||
|
|
||||||
@mpw.add(item)
|
@mpw.add(item)
|
||||||
@mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
|
@mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
|
||||||
@mpw.set_otp_key(item.id, options[:otp_key]) if options.has_key?(:otp_key)
|
@mpw.set_otp_key(item.id, options[:otp_key]) if options.has_key?(:otp_key)
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
host: # <%= I18n.t('form.add_item.host') %>
|
host: # <%= I18n.t('form.add_item.host') %>
|
||||||
user: # <%= I18n.t('form.add_item.login') %>
|
user: # <%= I18n.t('form.add_item.login') %>
|
||||||
group: # <%= I18n.t('form.add_item.group') %>
|
group: # <%= I18n.t('form.add_item.group') %>
|
||||||
protocol: # <%= I18n.t('form.add_item.protocol') %>
|
protocol: # <%= I18n.t('form.add_item.protocol') %><% if not password %>
|
||||||
password: # <%= I18n.t('form.add_item.password') %>
|
password: # <%= I18n.t('form.add_item.password') %><% end %>
|
||||||
port: # <%= I18n.t('form.add_item.port') %>
|
port: # <%= I18n.t('form.add_item.port') %>
|
||||||
comment: # <%= I18n.t('form.add_item.comment') %>
|
comment: # <%= I18n.t('form.add_item.comment') %>
|
||||||
otp_key: # <%= I18n.t('form.add_item.otp_key') %>
|
otp_key: # <%= I18n.t('form.add_item.otp_key') %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue