Skip to content

Commit

Permalink
1. fixes based on PR #11 comments;
Browse files Browse the repository at this point in the history
2. remove failed passcode attempts older than 30 days.
  • Loading branch information
G authored and G committed Mar 7, 2022
1 parent d8a7876 commit e4a1b7e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Telegram/Telegram-iOS/be.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Settings.Version" = "Telegram для iOS v%1$@ (%2$@)\nPTelegram версія %3$@";

"PasscodeSettings.BadAttempts" = "Няўдалыя спробы ўвода кода блакіроўкі";
"PasscodeSettings.BadAttempts.Info" = "Паглядзіце ўсе няўдалыя спробы ўводу кода блакіроўкі.";
"PasscodeSettings.BadAttempts.Help" = "Паглядзіце ўсе няўдалыя спробы ўводу кода блакіроўкі.";
"PasscodeSettings.BadAttempts.AppLogin" = "Разблакіроўка дадатка";
"PasscodeSettings.BadAttempts.SettingsLogin" = "Уваход у налады кода блакіроўкі";
"PasscodeSettings.BadAttempts.FakePasscode" = "Несапраўдны код блакіроўкі";
Expand Down
2 changes: 1 addition & 1 deletion Telegram/Telegram-iOS/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -7237,7 +7237,7 @@ Sorry for the inconvenience.";
"Settings.Version" = "Telegram for iOS v%1$@ (%2$@)\nPTelegram version %3$@";

"PasscodeSettings.BadAttempts" = "Bad Passcode Attempts";
"PasscodeSettings.BadAttempts.Info" = "See all bad passcode attempts";
"PasscodeSettings.BadAttempts.Help" = "See all bad passcode attempts";
"PasscodeSettings.BadAttempts.AppLogin" = "App Login";
"PasscodeSettings.BadAttempts.SettingsLogin" = "Settings Login";
"PasscodeSettings.BadAttempts.FakePasscode" = "Fake Passcode";
Expand Down
2 changes: 1 addition & 1 deletion Telegram/Telegram-iOS/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Settings.Version" = "Telegram для iOS v%1$@ (%2$@)\nPTelegram версия %3$@";

"PasscodeSettings.BadAttempts" = "Неудачные попытки ввода кода-пароля";
"PasscodeSettings.BadAttempts.Info" = "Посмотрите все неудачные попытки ввода кода-пароля.";
"PasscodeSettings.BadAttempts.Help" = "Посмотрите все неудачные попытки ввода кода-пароля.";
"PasscodeSettings.BadAttempts.AppLogin" = "Разблокировка приложения";
"PasscodeSettings.BadAttempts.SettingsLogin" = "Вход в настройки кода-пароля";
"PasscodeSettings.BadAttempts.FakePasscode" = "Ложный код-пароль";
Expand Down
16 changes: 11 additions & 5 deletions submodules/PasscodeUI/Sources/PasscodeEntryController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ public final class PasscodeEntryController: ViewController {
strongSelf.appLockContext.failedUnlockAttempt()
strongSelf.controllerNode.animateError()

let _ = updatePresentationPasscodeSettingsInteractively(accountManager: strongSelf.accountManager, { passcodeSettings in
var badPasscodeAttempts = passcodeSettings.badPasscodeAttempts ?? []
badPasscodeAttempts.append(BadPasscodeAttempt(type: BadPasscodeAttempt.AppUnlockType, isFakePasscode: false))
return passcodeSettings.withUpdatedBadPasscodeAttempts(badPasscodeAttempts)
}).start()
addBadPasscodeAttempt(accountManager: strongSelf.accountManager, bpa: BadPasscodeAttempt(type: BadPasscodeAttempt.AppUnlockType, isFakePasscode: false))
}
}
self.controllerNode.requestBiometrics = { [weak self] in
Expand Down Expand Up @@ -296,3 +292,13 @@ public final class PasscodeEntryController: ViewController {
}
}
}

public func addBadPasscodeAttempt(accountManager: AccountManager<TelegramAccountManagerTypes>, bpa: BadPasscodeAttempt) {
let _ = updatePresentationPasscodeSettingsInteractively(accountManager: accountManager, { passcodeSettings in
var badPasscodeAttempts = passcodeSettings.badPasscodeAttempts
let removeBeforeDate = CFAbsoluteTimeGetCurrent() - 30 * 24 * 60 * 60 // remove records older than 30 days
badPasscodeAttempts.removeAll(where: { $0.date < removeBeforeDate })
badPasscodeAttempts.append(bpa)
return passcodeSettings.withUpdatedBadPasscodeAttempts(badPasscodeAttempts)
}).start()
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ private func passcodeOptionsControllerEntries(presentationData: PresentationData
entries.append(.addFakePasscode(presentationData.theme, presentationData.strings.PasscodeSettings_AddFakePasscode))
entries.append(.fakePasscodeInfo(presentationData.theme, presentationData.strings.PasscodeSettings_FakePasscodeHelp))

entries.append(.badPasscodeAttempts(presentationData.theme, presentationData.strings.PasscodeSettings_BadAttempts, passcodeOptionsData.presentationSettings.badPasscodeAttempts?.count ?? 0))
entries.append(.badPasscodeAttemptsInfo(presentationData.theme, presentationData.strings.PasscodeSettings_BadAttempts_Info))
entries.append(.badPasscodeAttempts(presentationData.theme, presentationData.strings.PasscodeSettings_BadAttempts, passcodeOptionsData.presentationSettings.badPasscodeAttempts.count))
entries.append(.badPasscodeAttemptsInfo(presentationData.theme, presentationData.strings.PasscodeSettings_BadAttempts_Help))
}

return entries
Expand Down Expand Up @@ -535,10 +535,10 @@ func passcodeOptionsController(context: AccountContext) -> ViewController {
let bpaController = BadPasscodeAttemptsController(context: context)
bpaController.clear = {
let _ = (passcodeOptionsDataPromise.get() |> take(1)).start(next: { [weak passcodeOptionsDataPromise] data in
passcodeOptionsDataPromise?.set(.single(data.withUpdatedPresentationSettings(data.presentationSettings.withUpdatedBadPasscodeAttempts(nil))))
passcodeOptionsDataPromise?.set(.single(data.withUpdatedPresentationSettings(data.presentationSettings.withUpdatedBadPasscodeAttempts([]))))

let _ = updatePresentationPasscodeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current in
return current.withUpdatedBadPasscodeAttempts(nil)
return current.withUpdatedBadPasscodeAttempts([])
}).start()
})

Expand Down Expand Up @@ -615,11 +615,7 @@ public func passcodeOptionsAccessController(context: AccountContext, animateIn:
if succeed {
completion(true)
} else {
let _ = updatePresentationPasscodeSettingsInteractively(accountManager: context.sharedContext.accountManager, { passcodeSettings in
var badPasscodeAttempts = passcodeSettings.badPasscodeAttempts ?? []
badPasscodeAttempts.append(BadPasscodeAttempt(type: BadPasscodeAttempt.PasscodeSettingsType, isFakePasscode: false))
return passcodeSettings.withUpdatedBadPasscodeAttempts(badPasscodeAttempts)
}).start()
addBadPasscodeAttempt(accountManager: context.sharedContext.accountManager, bpa: BadPasscodeAttempt(type: BadPasscodeAttempt.PasscodeSettingsType, isFakePasscode: false))
}
return succeed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public struct BadPasscodeAttempt: Codable, Equatable {
public static let AppUnlockType: Int32 = 0
public static let PasscodeSettingsType: Int32 = 1

public var type: Int32
public var isFakePasscode: Bool
public var date: CFAbsoluteTime
public let type: Int32
public let isFakePasscode: Bool
public let date: CFAbsoluteTime

public init(type: Int32, isFakePasscode: Bool, date: CFAbsoluteTime = CFAbsoluteTimeGetCurrent()) {
self.type = type
Expand All @@ -24,13 +24,13 @@ public struct PresentationPasscodeSettings: Codable, Equatable {
public var biometricsDomainState: Data?
public var shareBiometricsDomainState: Data?

public var badPasscodeAttempts: [BadPasscodeAttempt]?
public var badPasscodeAttempts: [BadPasscodeAttempt]

public static var defaultSettings: PresentationPasscodeSettings {
return PresentationPasscodeSettings(enableBiometrics: false, autolockTimeout: nil, biometricsDomainState: nil, shareBiometricsDomainState: nil, badPasscodeAttempts: nil)
return PresentationPasscodeSettings(enableBiometrics: false, autolockTimeout: nil, biometricsDomainState: nil, shareBiometricsDomainState: nil, badPasscodeAttempts: [])
}

public init(enableBiometrics: Bool, autolockTimeout: Int32?, biometricsDomainState: Data?, shareBiometricsDomainState: Data?, badPasscodeAttempts: [BadPasscodeAttempt]?) {
public init(enableBiometrics: Bool, autolockTimeout: Int32?, biometricsDomainState: Data?, shareBiometricsDomainState: Data?, badPasscodeAttempts: [BadPasscodeAttempt]) {
self.enableBiometrics = enableBiometrics
self.autolockTimeout = autolockTimeout
self.biometricsDomainState = biometricsDomainState
Expand All @@ -47,7 +47,7 @@ public struct PresentationPasscodeSettings: Codable, Equatable {
self.biometricsDomainState = try container.decodeIfPresent(Data.self, forKey: "ds")
self.shareBiometricsDomainState = try container.decodeIfPresent(Data.self, forKey: "sds")

self.badPasscodeAttempts = try container.decodeIfPresent([BadPasscodeAttempt].self, forKey: "pt_bpa")
self.badPasscodeAttempts = try container.decodeIfPresent([BadPasscodeAttempt].self, forKey: "pt_bpa") ?? []
}

public func encode(to encoder: Encoder) throws {
Expand All @@ -58,7 +58,7 @@ public struct PresentationPasscodeSettings: Codable, Equatable {
try container.encodeIfPresent(self.biometricsDomainState, forKey: "ds")
try container.encodeIfPresent(self.shareBiometricsDomainState, forKey: "sds")

try container.encodeIfPresent(self.badPasscodeAttempts, forKey: "pt_bpa")
try container.encode(self.badPasscodeAttempts, forKey: "pt_bpa")
}

public static func ==(lhs: PresentationPasscodeSettings, rhs: PresentationPasscodeSettings) -> Bool {
Expand All @@ -81,7 +81,7 @@ public struct PresentationPasscodeSettings: Codable, Equatable {
return PresentationPasscodeSettings(enableBiometrics: self.enableBiometrics, autolockTimeout: autolockTimeout, biometricsDomainState: self.biometricsDomainState, shareBiometricsDomainState: shareBiometricsDomainState, badPasscodeAttempts: self.badPasscodeAttempts)
}

public func withUpdatedBadPasscodeAttempts(_ badPasscodeAttempts: [BadPasscodeAttempt]?) -> PresentationPasscodeSettings {
public func withUpdatedBadPasscodeAttempts(_ badPasscodeAttempts: [BadPasscodeAttempt]) -> PresentationPasscodeSettings {
return PresentationPasscodeSettings(enableBiometrics: self.enableBiometrics, autolockTimeout: self.autolockTimeout, biometricsDomainState: self.biometricsDomainState, shareBiometricsDomainState: self.shareBiometricsDomainState, badPasscodeAttempts: badPasscodeAttempts)
}
}
Expand Down

0 comments on commit e4a1b7e

Please sign in to comment.