Module: Lich::Common::GUI::MasterPasswordPrompt

Defined in:
documented/common/gui/master_password_prompt.rb

Class Method Summary collapse

Class Method Details

.show_create_master_password_dialogString?

Show the UI dialog to create a master password. This method prompts the user to create a master password and validates its strength.

Examples:

Creating a master password

password = Lich::Common::GUI::MasterPasswordPrompt.show_create_master_password_dialog

Returns:

  • (String, nil)

    The master password if created, or nil if canceled.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'documented/common/gui/master_password_prompt.rb', line 14

def self.show_create_master_password_dialog
  # Show UI dialog to user
  master_password = MasterPasswordPromptUI.show_dialog

  return nil if master_password.nil?

  # ====================================================================
  # VALIDATION: Check password requirements
  # ====================================================================
  if master_password.length < 8
    if show_warning_dialog(
      "Short Password",
      "Password is shorter than 8 characters.\n" +
      "Longer passwords (12+ chars) are stronger.\n\n" +
      "Continue with this password?"
    )
      # User chose to continue with weak password
      Lich.log "info: Master password strength validated (user override)"
      return master_password
    else
      # User declined weak password, restart
      Lich.log "info: User rejected weak password, prompting again"
      return show_create_master_password_dialog
    end
  end

  Lich.log "info: Master password strength validated"

  master_password
end

.show_enter_master_password_dialog(validation_test = nil) ⇒ String?

Show the UI dialog to enter a master password for recovery. This method prompts the user to enter their master password for recovery purposes.

Examples:

Entering a master password for recovery

password = Lich::Common::GUI::MasterPasswordPrompt.show_enter_master_password_dialog(validation_test)

Parameters:

  • validation_test (Object) (defaults to: nil)

    An optional validation test to verify the password.

Returns:

  • (String, nil)

    The entered master password if valid, or nil if canceled.



51
52
53
54
55
56
57
58
59
60
61
# File 'documented/common/gui/master_password_prompt.rb', line 51

def self.show_enter_master_password_dialog(validation_test = nil)
  # Show recovery UI dialog to user
  # Clearly indicates password recovery vs creation
  result = MasterPasswordPromptUI.show_recovery_dialog(validation_test)

  return nil if result.nil?

  Lich.log "info: Master password entered and validated for recovery"

  result
end

.show_warning_dialog(title, message) ⇒ Boolean

Show a warning dialog to the user. This method displays a modal dialog with a warning message and waits for user response.

Examples:

Showing a warning dialog

user_accepted = Lich::Common::GUI::MasterPasswordPrompt.show_warning_dialog("Warning Title", "This is a warning message.")

Parameters:

  • title (String)

    The title of the warning dialog.

  • message (String)

    The message to display in the dialog.

Returns:

  • (Boolean)

    True if the user clicked ‘Yes’, false if ‘No’.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'documented/common/gui/master_password_prompt.rb', line 83

def self.show_warning_dialog(title, message)
  # Block until dialog completes
  response = nil
  mutex = Mutex.new
  condition = ConditionVariable.new

  Gtk.queue do
    dialog = Gtk::MessageDialog.new(
      parent: nil,
      flags: :modal,
      type: :warning,
      buttons: :yes_no,
      message: title
    )
    dialog.secondary_text = message
    response = dialog.run
    dialog.destroy

    # Signal waiting thread
    mutex.synchronize { condition.signal }
  end

  # Wait for dialog to complete
  mutex.synchronize { condition.wait(mutex) }

  response == Gtk::ResponseType::YES
end

.validate_master_password(master_password, validation_test) ⇒ Boolean

Validate the provided master password against a validation test. This method checks if the given master password is valid based on the provided test.

Examples:

Validating a master password

is_valid = Lich::Common::GUI::MasterPasswordPrompt.validate_master_password(password, validation_test)

Parameters:

  • master_password (String)

    The master password to validate.

  • validation_test (Object)

    The validation test to use for verification.

Returns:

  • (Boolean)

    True if the password is valid, false otherwise.



70
71
72
73
74
# File 'documented/common/gui/master_password_prompt.rb', line 70

def self.validate_master_password(master_password, validation_test)
  return false if master_password.nil? || validation_test.nil?

  MasterPasswordManager.validate_master_password(master_password, validation_test)
end