Module: Lich::Common::GUI::PasswordManager
- Defined in:
- documented/common/gui/password_manager.rb
Class Method Summary collapse
-
.change_password(entry:, new_password:, account_name: nil, master_password: nil) ⇒ Hash
Changes the password for a given entry based on the specified encryption mode.
-
.get_password(entry:, account_name: nil, master_password: nil) ⇒ String
Retrieves the password for a given entry based on the specified encryption mode.
Class Method Details
.change_password(entry:, new_password:, account_name: nil, master_password: nil) ⇒ Hash
Changes the password for a given entry based on the specified encryption mode.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'documented/common/gui/password_manager.rb', line 22 def self.change_password(entry:, new_password:, account_name: nil, master_password: nil) mode = entry[:encryption_mode]&.to_sym || :plaintext case mode when :plaintext # Plaintext mode - store password directly entry[:password] = new_password when :standard # Standard mode - encrypt with account name raise ArgumentError, 'account_name required for standard mode' if account_name.nil? entry[:password] = PasswordCipher.encrypt( new_password, mode: :standard, account_name: account_name ) when :enhanced # Enhanced encryption mode - encrypt with master password raise ArgumentError, 'master_password required for enhanced mode' if master_password.nil? entry[:password] = PasswordCipher.encrypt( new_password, mode: :enhanced, master_password: master_password ) when :ssh_key # Certificate encryption mode - future feature, not yet implemented raise NotImplementedError, "#{mode} mode not yet implemented" else raise ArgumentError, "Unknown encryption mode: #{mode}" end entry end |
.get_password(entry:, account_name: nil, master_password: nil) ⇒ String
Retrieves the password for a given entry based on the specified encryption mode.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'documented/common/gui/password_manager.rb', line 68 def self.get_password(entry:, account_name: nil, master_password: nil) mode = entry[:encryption_mode]&.to_sym || :plaintext encrypted_password = entry[:password] case mode when :plaintext # Plaintext mode - return password directly encrypted_password when :standard # Standard mode - decrypt with account name raise ArgumentError, 'account_name required for standard mode' if account_name.nil? PasswordCipher.decrypt( encrypted_password, mode: :standard, account_name: account_name ) when :enhanced # Enhanced encryption mode - decrypt with master password raise ArgumentError, 'master_password required for enhanced mode' if master_password.nil? PasswordCipher.decrypt( encrypted_password, mode: :enhanced, master_password: master_password ) when :ssh_key # Certificate encryption mode - future feature, not yet implemented raise NotImplementedError, "#{mode} mode not yet implemented" else raise ArgumentError, "Unknown encryption mode: #{mode}" end end |