Fix password menu stickiness before first auth (#21295)

This commit is contained in:
ellensp 2021-03-11 11:02:35 +13:00 committed by Scott Lahteine
parent 059e6514ca
commit 894688c547
3 changed files with 18 additions and 10 deletions

View File

@ -31,7 +31,7 @@
Password password; Password password;
// public: // public:
bool Password::is_set, Password::is_locked; bool Password::is_set, Password::is_locked, Password::did_first_run; // = false
uint32_t Password::value, Password::value_entry; uint32_t Password::value, Password::value_entry;
// //
@ -47,11 +47,14 @@ void Password::lock_machine() {
// Authentication check // Authentication check
// //
void Password::authentication_check() { void Password::authentication_check() {
if (value_entry == value) if (value_entry == value) {
is_locked = false; is_locked = false;
else did_first_run = true;
}
else {
is_locked = true;
SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD); SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD);
}
TERN_(HAS_LCD_MENU, authentication_done()); TERN_(HAS_LCD_MENU, authentication_done());
} }

View File

@ -25,10 +25,10 @@
class Password { class Password {
public: public:
static bool is_set, is_locked; static bool is_set, is_locked, did_first_run;
static uint32_t value, value_entry; static uint32_t value, value_entry;
Password() { is_locked = false; } Password() {}
static void lock_machine(); static void lock_machine();
static void authentication_check(); static void authentication_check();

View File

@ -44,12 +44,18 @@ static uint8_t digit_no;
// Screen for both editing and setting the password // Screen for both editing and setting the password
// //
void Password::menu_password_entry() { void Password::menu_password_entry() {
ui.defer_status_screen(!did_first_run); // No timeout to status before first auth
START_MENU(); START_MENU();
// "Login" or "New Code" // "Login" or "New Code"
STATIC_ITEM_P(authenticating ? GET_TEXT(MSG_LOGIN_REQUIRED) : GET_TEXT(MSG_EDIT_PASSWORD), SS_CENTER|SS_INVERT); STATIC_ITEM_P(authenticating ? GET_TEXT(MSG_LOGIN_REQUIRED) : GET_TEXT(MSG_EDIT_PASSWORD), SS_CENTER|SS_INVERT);
STATIC_ITEM_P(NUL_STR, SS_CENTER|SS_INVERT, string); STATIC_ITEM_P(NUL_STR, SS_CENTER, string);
#if HAS_MARLINUI_U8GLIB
STATIC_ITEM_P(NUL_STR, SS_CENTER, "");
#endif
// Make the digit edit item look like a sub-menu // Make the digit edit item look like a sub-menu
PGM_P const label = GET_TEXT(MSG_ENTER_DIGIT); PGM_P const label = GET_TEXT(MSG_ENTER_DIGIT);
@ -57,7 +63,7 @@ void Password::menu_password_entry() {
MENU_ITEM_ADDON_START(utf8_strlen_P(label) + 1); MENU_ITEM_ADDON_START(utf8_strlen_P(label) + 1);
lcd_put_wchar(' '); lcd_put_wchar(' ');
lcd_put_wchar('1' + digit_no); lcd_put_wchar('1' + digit_no);
SETCURSOR_X(LCD_WIDTH - 1); SETCURSOR_X(LCD_WIDTH - 2);
lcd_put_wchar('>'); lcd_put_wchar('>');
MENU_ITEM_ADDON_END(); MENU_ITEM_ADDON_END();
@ -104,7 +110,7 @@ void Password::screen_password_entry() {
value_entry = 0; value_entry = 0;
digit_no = 0; digit_no = 0;
editable.uint8 = 0; editable.uint8 = 0;
memset(string, '-', PASSWORD_LENGTH); memset(string, '_', PASSWORD_LENGTH);
string[PASSWORD_LENGTH] = '\0'; string[PASSWORD_LENGTH] = '\0';
menu_password_entry(); menu_password_entry();
} }
@ -120,7 +126,6 @@ void Password::authenticate_user(const screenFunc_t in_succ_scr, const screenFun
if (is_set) { if (is_set) {
authenticating = true; authenticating = true;
ui.goto_screen(screen_password_entry); ui.goto_screen(screen_password_entry);
ui.defer_status_screen();
ui.update(); ui.update();
} }
else { else {