Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit ff35599

Browse files
authored
Merge pull request #16 from DutchCodingCompany/feature/change_retries_to_tries
Change maxRetries to maxTries
2 parents ac27f0a + 71f7302 commit ff35599

File tree

4 files changed

+153
-205
lines changed

4 files changed

+153
-205
lines changed

lib/pin_lock.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ class PinLock {
4848
required UserId userId,
4949
Duration? lockedOutDuration,
5050
Duration? lockAfterDuration,
51-
int? maxRetries,
51+
int? maxTries,
5252
int? pinLength,
5353
}) =>
5454
AuthenticatorImpl(
5555
repository,
5656
biometricAuthenticator,
5757
lockController,
58-
maxRetries ?? 5,
58+
maxTries ?? 5,
5959
lockedOutDuration ?? const Duration(minutes: 1),
6060
lockAfterDuration ?? const Duration(seconds: 5),
6161
pinLength ?? 4,

lib/src/entities/authenticator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ abstract class Authenticator with WidgetsBindingObserver {
1717

1818
/// The number of times that a pin can be entered incorrectly, before the app
1919
/// stops accepting unlock attempts for [lockedOutDuration]
20-
int get maxRetries;
20+
int get maxTries;
2121

2222
/// A duration for which the app will be locked after the number of times the pin is
23-
/// entered incorrectly exceeds [maxRetries]
23+
/// entered incorrectly exceeds [maxTries]
2424
Duration get lockedOutDuration;
2525

2626
/// The expected lenght of the pin, used to draw the [PinInputWidget]

lib/src/entities/authenticator_impl.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AuthenticatorImpl with WidgetsBindingObserver implements Authenticator {
1010
@override
1111
final Duration lockedOutDuration;
1212
@override
13-
final int maxRetries;
13+
final int maxTries;
1414
@override
1515
final int pinLength;
1616
@override
@@ -30,7 +30,7 @@ class AuthenticatorImpl with WidgetsBindingObserver implements Authenticator {
3030
this._repository,
3131
this._biometricAuth,
3232
this._lockController,
33-
this.maxRetries,
33+
this.maxTries,
3434
this.lockedOutDuration,
3535
this.lockAfterDuration,
3636
this.pinLength,
@@ -255,6 +255,9 @@ class AuthenticatorImpl with WidgetsBindingObserver implements Authenticator {
255255
final userPin = await _repository.getPin(forUser: userId);
256256
if (userPin?.value != pin.value) {
257257
await _repository.addFailedAttempt(DateTime.now(), forUser: userId);
258+
if (await _isLockedDueToTooManyAttempts()) {
259+
return const Left(LocalAuthFailure.tooManyAttempts);
260+
}
258261
return const Left(LocalAuthFailure.wrongPin);
259262
}
260263
await _repository.resetFailedAttempts(ofUser: userId);
@@ -313,6 +316,9 @@ class AuthenticatorImpl with WidgetsBindingObserver implements Authenticator {
313316
final userPin = await _repository.getPin(forUser: userId);
314317
if (userPin?.value != pin.value) {
315318
await _repository.addFailedAttempt(DateTime.now(), forUser: userId);
319+
if (await _isLockedDueToTooManyAttempts()) {
320+
return false;
321+
}
316322
return false;
317323
}
318324
await _repository.resetFailedAttempts(ofUser: userId);
@@ -328,7 +334,7 @@ class AuthenticatorImpl with WidgetsBindingObserver implements Authenticator {
328334

329335
Future<bool> _isLockedDueToTooManyAttempts() async {
330336
final failedAttemptsList = await _repository.getListOfFailedAttempts(userId: userId);
331-
if (failedAttemptsList.length > maxRetries) {
337+
if (failedAttemptsList.length >= maxTries) {
332338
if (DateTime.now().difference(failedAttemptsList.last) < lockedOutDuration) {
333339
return true;
334340
}

0 commit comments

Comments
 (0)