diff --git a/src/nemo-devicelock/host/hostauthenticator.cpp b/src/nemo-devicelock/host/hostauthenticator.cpp index bedfdf1..892bd35 100644 --- a/src/nemo-devicelock/host/hostauthenticator.cpp +++ b/src/nemo-devicelock/host/hostauthenticator.cpp @@ -302,38 +302,27 @@ void HostAuthenticator::handleClearSecurityCode(const QString &client) void HostAuthenticator::enterSecurityCode(const QString &code) { - int attempts = 0; - switch (m_state) { case Idle: return; case Authenticating: case RequestingPermission: qCDebug(daemon, "Security code entered for authentication."); - switch ((attempts = checkCode(code))) { - case Success: - case SecurityCodeExpired: - confirmAuthentication(Authenticator::SecurityCode); - return; - case LockedOut: - lockedOut(); - return; - } - break; - case AuthenticatingForChange: + checkCodeFinished(checkCode(code)); + return; + case AuthenticatingForChange: { qCDebug(daemon, "Security code entered for code change authentication."); - switch ((attempts = checkCode(code))) { + int result = checkCode(code); + switch (result) { + case Evaluating: case Success: case SecurityCodeExpired: m_currentCode = code; - enterCodeChangeState(&HostAuthenticationInput::feedback, Authenticator::SecurityCode); - - return; - case LockedOut: - lockedOut(); - return; + break; } - break; + checkCodeFinished(result); + return; + } case EnteringNewSecurityCode: qCDebug(daemon, "New security code entered."); m_newCode = code; @@ -380,32 +369,19 @@ void HostAuthenticator::enterSecurityCode(const QString &code) } case AuthenticatingForClear: { qCDebug(daemon, "Security code entered for clear authentication."); - if ((attempts = checkCode(code)) == 0) { - if (clearCode(code)) { - securityCodeCleared(); - } else { - abortAuthentication(AuthenticationInput::SoftwareError); - } - return; + int result = checkCode(code); + switch (result) { + case Evaluating: + case Success: + m_currentCode = code; + break; } - break; + checkCodeFinished(result); + return; } default: return; } - - const int maximum = maximumAttempts(); - - if (maximum > 0 && attempts > 0) { - feedback(AuthenticationInput::IncorrectSecurityCode, qMax(0, maximum - attempts)); - - if (attempts >= maximum) { - lockedOut(); - return; - } - } else { - feedback(AuthenticationInput::IncorrectSecurityCode, -1); - } } void HostAuthenticator::requestSecurityCode() @@ -435,6 +411,70 @@ void HostAuthenticator::authorize() } } +void HostAuthenticator::checkCodeFinished(int result) +{ + switch (m_state) { + case Authenticating: + case RequestingPermission: + switch (result) { + case Evaluating: + return; + case Success: + case SecurityCodeExpired: + confirmAuthentication(Authenticator::SecurityCode); + return; + case LockedOut: + lockedOut(); + return; + } + break; + case AuthenticatingForChange: + switch (result) { + case Evaluating: + return; + case Success: + case SecurityCodeExpired: + enterCodeChangeState(&HostAuthenticationInput::feedback, Authenticator::SecurityCode); + return; + case LockedOut: + lockedOut(); + return; + } + break; + case AuthenticatingForClear: { + switch (result) { + case Evaluating: + return; + case Success: + if (clearCode(m_currentCode)) { + securityCodeCleared(); + } else { + abortAuthentication(AuthenticationInput::SoftwareError); + } + m_currentCode.clear(); + return; + break; + } + } + default: + return; + } + + const int attempts = result; + const int maximum = maximumAttempts(); + + if (maximum > 0 && attempts > 0) { + feedback(AuthenticationInput::IncorrectSecurityCode, qMax(0, maximum - attempts)); + + if (attempts >= maximum) { + lockedOut(); + return; + } + } else { + feedback(AuthenticationInput::IncorrectSecurityCode, -1); + } +} + void HostAuthenticator::setCodeFinished(int result) { switch (result) { @@ -588,6 +628,7 @@ void HostAuthenticator::securityCodeCleared() void HostAuthenticator::securityCodeClearAborted() { + m_currentCode.clear(); sendToActiveClient(securityCodeInterface, QStringLiteral("ClearAborted")); authenticationEnded(false); } diff --git a/src/nemo-devicelock/host/hostauthenticator.h b/src/nemo-devicelock/host/hostauthenticator.h index f040e32..c3239e6 100644 --- a/src/nemo-devicelock/host/hostauthenticator.h +++ b/src/nemo-devicelock/host/hostauthenticator.h @@ -129,6 +129,7 @@ class HostAuthenticator : public HostAuthenticationInput Authenticator::Methods methods, uint authenticatingPid, AuthenticationInput::Feedback feedback) override; void authenticationEnded(bool confirmed) override; + void checkCodeFinished(int result); void setCodeFinished(int result); // Signals