mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50: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
|
||||
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|
|
||||
options[:wallet] = wallet
|
||||
end
|
||||
|
@ -48,4 +52,4 @@ cli = MPW::Cli.new(config, options[:sync])
|
|||
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.add
|
||||
cli.add(options[:password])
|
||||
|
|
|
@ -368,7 +368,11 @@ class Cli
|
|||
puts "#{I18n.t('display.error')} #15: #{e}".red
|
||||
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'
|
||||
options = {}
|
||||
opts = {}
|
||||
|
@ -397,10 +401,15 @@ class Cli
|
|||
end
|
||||
|
||||
# Form to add a new item
|
||||
def add
|
||||
options = text_editor('add_form')
|
||||
# @args: password -> generate a random password
|
||||
def add(password=false)
|
||||
options = text_editor('add_form', nil, password)
|
||||
item = Item.new(options)
|
||||
|
||||
if password
|
||||
options[:password] = MPW::password(length: 24)
|
||||
end
|
||||
|
||||
@mpw.add(item)
|
||||
@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)
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
host: # <%= I18n.t('form.add_item.host') %>
|
||||
user: # <%= I18n.t('form.add_item.login') %>
|
||||
group: # <%= I18n.t('form.add_item.group') %>
|
||||
protocol: # <%= I18n.t('form.add_item.protocol') %>
|
||||
password: # <%= I18n.t('form.add_item.password') %>
|
||||
protocol: # <%= I18n.t('form.add_item.protocol') %><% if not password %>
|
||||
password: # <%= I18n.t('form.add_item.password') %><% end %>
|
||||
port: # <%= I18n.t('form.add_item.port') %>
|
||||
comment: # <%= I18n.t('form.add_item.comment') %>
|
||||
otp_key: # <%= I18n.t('form.add_item.otp_key') %>
|
||||
|
|
Loading…
Add table
Reference in a new issue