mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Don't allow to bypass passcode by changing time
This commit is contained in:
parent
9978ef6725
commit
be87379a4e
@ -11,6 +11,7 @@ import AccountContext
|
|||||||
import LocalAuth
|
import LocalAuth
|
||||||
import AppBundle
|
import AppBundle
|
||||||
import PasscodeInputFieldNode
|
import PasscodeInputFieldNode
|
||||||
|
import MonotonicTime
|
||||||
|
|
||||||
private let titleFont = Font.regular(20.0)
|
private let titleFont = Font.regular(20.0)
|
||||||
private let subtitleFont = Font.regular(15.0)
|
private let subtitleFont = Font.regular(15.0)
|
||||||
@ -194,7 +195,14 @@ final class PasscodeEntryControllerNode: ASDisplayNode {
|
|||||||
private func shouldWaitBeforeNextAttempt() -> Bool {
|
private func shouldWaitBeforeNextAttempt() -> Bool {
|
||||||
if let attempts = self.invalidAttempts {
|
if let attempts = self.invalidAttempts {
|
||||||
if attempts.count >= 6 {
|
if attempts.count >= 6 {
|
||||||
if Int32(CFAbsoluteTimeGetCurrent()) - attempts.timestamp < waitInterval {
|
var bootTimestamp: Int32 = 0
|
||||||
|
let uptime = getDeviceUptimeSeconds(&bootTimestamp)
|
||||||
|
|
||||||
|
if attempts.bootTimestamp != bootTimestamp {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if uptime - attempts.uptime < waitInterval {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
@ -215,10 +223,13 @@ final class PasscodeEntryControllerNode: ASDisplayNode {
|
|||||||
text = NSAttributedString(string: self.strings.PasscodeSettings_TryAgainIn1Minute, font: subtitleFont, textColor: .white)
|
text = NSAttributedString(string: self.strings.PasscodeSettings_TryAgainIn1Minute, font: subtitleFont, textColor: .white)
|
||||||
|
|
||||||
self.timer?.invalidate()
|
self.timer?.invalidate()
|
||||||
let timer = SwiftSignalKit.Timer(timeout: Double(attempts.timestamp + waitInterval - Int32(CFAbsoluteTimeGetCurrent())), repeat: false, completion: { [weak self] in
|
let timer = SwiftSignalKit.Timer(timeout: 1.0, repeat: true, completion: { [weak self] in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
strongSelf.timer = nil
|
if !strongSelf.shouldWaitBeforeNextAttempt() {
|
||||||
strongSelf.updateInvalidAttempts(strongSelf.invalidAttempts, animated: true)
|
strongSelf.updateInvalidAttempts(strongSelf.invalidAttempts, animated: true)
|
||||||
|
strongSelf.timer?.invalidate()
|
||||||
|
strongSelf.timer = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, queue: Queue.mainQueue())
|
}, queue: Queue.mainQueue())
|
||||||
self.timer = timer
|
self.timer = timer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user