Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multiple issues in password feature #21295

Merged
merged 4 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Marlin/src/feature/password/password.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Password password;

// 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;

//
Expand All @@ -47,11 +47,14 @@ void Password::lock_machine() {
// Authentication check
//
void Password::authentication_check() {
if (value_entry == value)
if (value_entry == value) {
is_locked = false;
else
did_first_run = true;
}
else {
is_locked = true;
SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD);

}
TERN_(HAS_LCD_MENU, authentication_done());
}

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/password/password.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

class Password {
public:
static bool is_set, is_locked;
static bool is_set, is_locked, did_first_run;
static uint32_t value, value_entry;

Password() { is_locked = false; }
Password() {}

static void lock_machine();
static void authentication_check();
Expand Down
13 changes: 9 additions & 4 deletions Marlin/src/lcd/menu/menu_password.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,26 @@ static uint8_t digit_no;
// Screen for both editing and setting the password
//
void Password::menu_password_entry() {
ui.defer_status_screen(!did_first_run); // No timeout to status before first auth

START_MENU();

// "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(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
PGM_P const label = GET_TEXT(MSG_ENTER_DIGIT);
EDIT_ITEM_P(uint8, label, &editable.uint8, 0, 9, digit_entered);
MENU_ITEM_ADDON_START(utf8_strlen_P(label) + 1);
lcd_put_wchar(' ');
lcd_put_wchar('1' + digit_no);
SETCURSOR_X(LCD_WIDTH - 1);
SETCURSOR_X(LCD_WIDTH - 2);
lcd_put_wchar('>');
MENU_ITEM_ADDON_END();

Expand Down Expand Up @@ -104,7 +110,7 @@ void Password::screen_password_entry() {
value_entry = 0;
digit_no = 0;
editable.uint8 = 0;
memset(string, '-', PASSWORD_LENGTH);
memset(string, '_', PASSWORD_LENGTH);
string[PASSWORD_LENGTH] = '\0';
menu_password_entry();
}
Expand All @@ -120,7 +126,6 @@ void Password::authenticate_user(const screenFunc_t in_succ_scr, const screenFun
if (is_set) {
authenticating = true;
ui.goto_screen(screen_password_entry);
ui.defer_status_screen();
ui.update();
}
else {
Expand Down