Class: PasswordManager

Inherits:
Object
  • Object
show all
Includes:
Aes, LockrFileUtils
Defined in:
lib/lockr/pwdmgr.rb

Constant Summary collapse

NUM_BACKUP_FILES =
3

Instance Method Summary collapse

Methods included from LockrFileUtils

calculate_sha512_hash, copy, #load_from_vault, load_obj_yaml, rotate_file, #save_to_vault, store_obj_yaml

Methods included from Aes

#decrypt, #derive_key_iv, #encrypt

Constructor Details

#initialize(keyfile, vault) ⇒ PasswordManager

Returns a new instance of PasswordManager.



12
13
14
15
16
17
# File 'lib/lockr/pwdmgr.rb', line 12

def initialize( keyfile, vault)
  puts "Initializing Password manager module. Vault: '#{vault}', Keyfile: '...'"
  @vault_file = vault
  @keyfile = keyfile
  @scheduler = Rufus::Scheduler.new
end

Instance Method Details

#add(id, username, password, url) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lockr/pwdmgr.rb', line 45

def add( id, username, password, url)
  vault = decrypt_vault()
  site_dir = {}
  
  # get site directory
  if vault.has_key?( id)
    site_dir = vault[id]
  end
  
  new_store = PasswordStore.new( id, url, username, password)
  site_dir[username] = new_store
  vault[id] = site_dir
  
  encrypt_vault( vault)
  puts 'Added new id/username combination'
  return new_store
end

#change(id, username, password, url) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/lockr/pwdmgr.rb', line 63

def change( id, username, password, url)
  vault = decrypt_vault()
  site_dir = vault[id]
  site_dir[username].password = password if ! password.nil?
  site_dir[username].url = url if ! url.nil?
  
  encrypt_vault( vault)
  puts 'Changed password'
end

#copy_to_clipboard(id, username) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lockr/pwdmgr.rb', line 23

def copy_to_clipboard( id, username)
  vault = decrypt_vault()
  
  Clipboard.copy vault[id][username].password
  puts 'Password copied to clipboard'
  
  if @job != nil
    begin
      @scheduler.unschedule( @job)
      puts 'Unscheduled old clear task'
    rescue ArgumentError
      # job no longer active
    end 
  end
  
  puts 'Scheduling clipboard reset in 15 seconds'
  @job = @scheduler.in '15s' do
    Clipboard.copy ' '
    puts 'Clipboard cleared'
  end
end

#delete(id, username) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lockr/pwdmgr.rb', line 73

def delete( id, username)
  vault = decrypt_vault()
  site_dir = vault[id]
  
  site_dir.delete( username)
  
  if ( site_dir.size == 0 )
    vault.delete( id)
  end
  
  encrypt_vault( vault)
  puts 'Deleted password'
end

#listObject



19
20
21
# File 'lib/lockr/pwdmgr.rb', line 19

def list()
  return decrypt_vault()
end