diff --git a/Userland/Applications/Escalator/EscalatorWindow.cpp b/Userland/Applications/Escalator/EscalatorWindow.cpp index 615d3fcb68..16b022b29f 100644 --- a/Userland/Applications/Escalator/EscalatorWindow.cpp +++ b/Userland/Applications/Escalator/EscalatorWindow.cpp @@ -54,12 +54,20 @@ EscalatorWindow::EscalatorWindow(StringView executable, Vector argum m_icon_image_widget->set_bitmap(app_icon.bitmap_for_size(32)); m_ok_button = *main_widget->find_descendant_of_type_named("ok_button"); - m_ok_button->on_click = [this](auto) { - auto result = check_password(); - if (result.is_error()) { - GUI::MessageBox::show_error(this, ByteString::formatted("Failed to execute command: {}", result.error())); + size_t password_attempts = 0; + m_ok_button->on_click = [this, password_attempts](auto) mutable { + if (check_password()) { + auto result = execute_command(); + if (result.is_error()) { + GUI::MessageBox::show_error(this, ByteString::formatted("Failed to execute command: {}", result.error())); + } + close(); + } else { + if (++password_attempts >= 3) { + GUI::MessageBox::show_error(this, ByteString::formatted("Too many failed attempts")); + close(); + } } - close(); }; m_ok_button->set_default(true); @@ -72,12 +80,12 @@ EscalatorWindow::EscalatorWindow(StringView executable, Vector argum m_password_input->set_focus(true); } -ErrorOr EscalatorWindow::check_password() +bool EscalatorWindow::check_password() { ByteString password = m_password_input->text(); if (password.is_empty()) { GUI::MessageBox::show_error(this, "Please enter a password."sv); - return {}; + return false; } // FIXME: PasswordBox really should store its input directly as a SecretString. @@ -85,12 +93,10 @@ ErrorOr EscalatorWindow::check_password() if (!m_current_user.authenticate(password_secret)) { GUI::MessageBox::show_error(this, "Incorrect or disabled password."sv); m_password_input->select_all(); - return {}; + return false; } - // Caller will close Escalator if error is returned. - TRY(execute_command()); - return {}; + return true; } ErrorOr EscalatorWindow::execute_command() diff --git a/Userland/Applications/Escalator/EscalatorWindow.h b/Userland/Applications/Escalator/EscalatorWindow.h index 108e0c4b1c..892ef1492b 100644 --- a/Userland/Applications/Escalator/EscalatorWindow.h +++ b/Userland/Applications/Escalator/EscalatorWindow.h @@ -36,7 +36,7 @@ public: private: EscalatorWindow(StringView executable, Vector arguments, Options const& options); - ErrorOr check_password(); + bool check_password(); Vector m_arguments; StringView m_executable;