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?

Shows a dialog for the user to create a master password.

Examples:

Create a master password dialog

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

Returns:

  • (String, nil)

    the created master password 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?

Shows a dialog for the user to enter a master password for recovery. Clearly indicates password recovery vs creation.

Examples:

Show enter master password dialog

master_password = Lich::Common::GUI::MasterPasswordPrompt.show_enter_master_password_dialog

Parameters:

  • validation_test (String, nil) (defaults to: nil)

    optional test for validating the entered password

Returns:

  • (String, nil)

    the entered master password or nil if canceled



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

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

Displays a warning dialog to the user and waits for a response.

Examples:

Show a warning dialog

user_confirmed = Lich::Common::GUI::MasterPasswordPrompt.show_warning_dialog("Warning", "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 confirms, false otherwise



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
110
# File 'documented/common/gui/master_password_prompt.rb', line 84

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

Validates the provided master password against a validation test.

Examples:

Validate a master password

is_valid = Lich::Common::GUI::MasterPasswordPrompt.validate_master_password("my_password", "test")

Parameters:

  • master_password (String)

    the master password to validate

  • validation_test (String)

    the test to validate against

Returns:

  • (Boolean)

    true if the password is valid, false otherwise



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

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