diff --git a/commands/login.c b/commands/login.c index bf5085c85..ee3c31ee1 100644 --- a/commands/login.c +++ b/commands/login.c @@ -25,6 +25,7 @@ #include #include #include +#include #define PASSWD_MAX_LENGTH (128 + 1) @@ -44,6 +45,7 @@ static int do_login(int argc, char *argv[]) int passwd_len, opt; int timeout = login_timeout; char *timeout_cmd = "boot"; + uint64_t start; console_allow_input(true); if (!is_passwd_enable()) { @@ -62,19 +64,21 @@ static int do_login(int argc, char *argv[]) if (optind != argc) timeout_cmd = argv[optind]; + start = get_time_ns(); do { puts("Password: "); passwd_len = password(passwd, PASSWD_MAX_LENGTH, LOGIN_MODE, timeout); - if (passwd_len < 0) { - console_allow_input(false); - run_command(timeout_cmd); - } + if (passwd_len < 0) + goto trigger_timeout; if (check_passwd(passwd, passwd_len) == 1) return 0; - } while(1); + } while(!is_timeout(start, timeout * SECOND) || timeout == 0); +trigger_timeout: + console_allow_input(false); + run_command(timeout_cmd); return 0; }