Skip to content

Commit ba70b2c

Browse files
authored
Merge pull request #22 from happylance/master
Fixed a security issue
2 parents 7510e66 + a03016e commit ba70b2c

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

PasscodeLock/PasscodeLock/EnterPasscodeState.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ struct EnterPasscodeState: PasscodeLockStateType {
1717
let isCancellableAction: Bool
1818
var isTouchIDAllowed = true
1919

20-
private var inccorectPasscodeAttempts = 0
20+
static let incorrectPasscodeAttemptsKey = "incorrectPasscodeAttempts"
21+
static var incorrectPasscodeAttempts: Int {
22+
get {
23+
return NSUserDefaults.standardUserDefaults().integerForKey(incorrectPasscodeAttemptsKey)
24+
}
25+
set {
26+
NSUserDefaults.standardUserDefaults().setInteger(newValue, forKey: incorrectPasscodeAttemptsKey)
27+
}
28+
}
29+
30+
2131
private var isNotificationSent = false
2232

2333
init(allowCancellation: Bool = false) {
@@ -33,21 +43,25 @@ struct EnterPasscodeState: PasscodeLockStateType {
3343
return
3444
}
3545

46+
var incorrectPasscodeAttempts = EnterPasscodeState.incorrectPasscodeAttempts
3647
if passcode == currentPasscode {
3748

3849
lock.delegate?.passcodeLockDidSucceed(lock)
39-
50+
incorrectPasscodeAttempts = 0
4051
} else {
4152

42-
inccorectPasscodeAttempts += 1
53+
incorrectPasscodeAttempts += 1
4354

44-
if inccorectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts {
55+
if incorrectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts {
4556

4657
postNotification()
58+
incorrectPasscodeAttempts = 0
4759
}
4860

4961
lock.delegate?.passcodeLockDidFail(lock)
5062
}
63+
64+
EnterPasscodeState.incorrectPasscodeAttempts = incorrectPasscodeAttempts
5165
}
5266

5367
private mutating func postNotification() {

PasscodeLock/PasscodeLock/PasscodeLock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class PasscodeLock: PasscodeLockType {
8989
dispatch_async(dispatch_get_main_queue()) {
9090

9191
if success {
92-
92+
EnterPasscodeState.incorrectPasscodeAttempts = 0
9393
self.delegate?.passcodeLockDidSucceed(self)
9494
}
9595
}

0 commit comments

Comments
 (0)