Logout automatically when pin/biometrics provided wrong too many times

This commit is contained in:
ismailgulek
2020-09-29 16:57:46 +03:00
parent ab9cc7655e
commit 7dc70b363f
7 changed files with 77 additions and 13 deletions

View File

@@ -41,6 +41,7 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
weak var viewDelegate: EnterPinCodeViewModelViewDelegate?
weak var coordinatorDelegate: EnterPinCodeViewModelCoordinatorDelegate?
private let pinCodePreferences: PinCodePreferences
private let localAuthenticationService: LocalAuthenticationService
// MARK: - Setup
@@ -49,6 +50,7 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
self.originalViewMode = viewMode
self.viewMode = viewMode
self.pinCodePreferences = pinCodePreferences
self.localAuthenticationService = LocalAuthenticationService(pinCodePreferences: pinCodePreferences)
}
// MARK: - Public
@@ -141,6 +143,12 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
if currentPin != pinCodePreferences.pin {
// no match
numberOfFailuresDuringEnterPIN += 1
pinCodePreferences.numberOfPinFailures += 1
if viewMode == .unlock && localAuthenticationService.shouldLogOutUser() {
// log out user
self.coordinatorDelegate?.enterPinCodeViewModelDidCompleteWithReset(self)
return
}
if numberOfFailuresDuringEnterPIN < pinCodePreferences.allowedNumberOfTrialsBeforeAlert {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.viewDelegate?.enterPinCodeViewModel(self, didUpdateViewState: .wrongPin)
@@ -153,6 +161,9 @@ final class EnterPinCodeViewModel: EnterPinCodeViewModelType {
}
} else {
// match
// we can use biometrics anymore, if set
pinCodePreferences.canUseBiometricsToUnlock = nil
pinCodePreferences.resetCounters()
// complete with a little delay
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.coordinatorDelegate?.enterPinCodeViewModelDidComplete(self)