1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 02:33:19 +00:00

add random password for update

This commit is contained in:
Adrien Waksberg 2017-02-26 23:12:49 +01:00
parent e4fb780016
commit 6b8dce2eff
3 changed files with 16 additions and 13 deletions

View file

@ -52,6 +52,10 @@ OptionParser.new do |opts|
values[:pattern] = pattern
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
@ -63,4 +67,4 @@ cli = MPW::Cli.new(config, options[:sync])
cli.load_config
cli.get_wallet(options[:wallet])
cli.decrypt
cli.update(values)
cli.update(options[:password], values)

View file

@ -425,10 +425,7 @@ class Cli
def add(password=false)
options = text_editor('add_form', nil, password)
item = Item.new(options)
if password
options[:password] = MPW::password(@config.password)
end
options[:password] = MPW::password(@config.password) if password
@mpw.add(item)
@mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
@ -442,8 +439,9 @@ class Cli
end
# Update an item
# @args: options -> the option to search
def update(options={})
# @args: password -> generate a random password
# options -> the option to search
def update(password=false, options={})
items = @mpw.list(options)
if items.length == 0
@ -452,7 +450,8 @@ class Cli
table_items(items) if items.length > 1
item = get_item(items)
options = text_editor('update_form', item)
options = text_editor('update_form', item, password)
options[:password] = MPW::password(@config.password) if password
item.update(options)
@mpw.set_password(item.id, options[:password]) if options.has_key?(:password)

View file

@ -2,9 +2,9 @@
# <%= I18n.t('form.update_item.host') %>
host: <%= item.host %>
# <%= I18n.t('form.update_item.login') %>
user: <%= item.user %>
user: <%= item.user %><% if not password %>
# <%= I18n.t('form.update_item.password') %>
password:
password: <% end %>
# <%= I18n.t('form.update_item.group') %>
group: <%= item.group %>
# <%= I18n.t('form.update_item.protocol') %>