Disallow eastern arabic numerals in passcode setup

Try to match western arabic passcode with eastern arabic for users who already stuck
This commit is contained in:
Ilya Laktyushin 2019-07-02 20:04:07 +02:00
parent 241fa6966a
commit 1e319a74fc
5 changed files with 30 additions and 2 deletions

View File

@ -0,0 +1,10 @@
import Foundation
func convertToArabicNumeralString(_ string: String) -> String {
var string = string
let arabicNumbers = ["٠": "0", "١": "1", "٢": "2", "٣": "3", "٤": "4", "٥": "5", "٦": "6", "٧": "7", "٨": "8", "٩": "9"]
for (arabic, generic) in arabicNumbers {
string = string.replacingOccurrences(of: generic, with: arabic)
}
return string
}

View File

@ -122,6 +122,9 @@ final public class PasscodeEntryController: ViewController {
succeed = true
case let .numericalPassword(code, _, _):
succeed = passcode == code
if !succeed {
succeed = convertToArabicNumeralString(passcode) == code
}
case let .plaintextPassword(code, _, _):
succeed = passcode == code
}

View File

@ -47,6 +47,10 @@ private func generateFieldBackgroundImage(background: PasscodeBackground, frame:
})
}
private let validDigitsSet: CharacterSet = {
return CharacterSet(charactersIn: "0".unicodeScalars.first! ... "9".unicodeScalars.first!)
}()
enum PasscodeEntryFieldType {
case digits6
case digits4
@ -66,7 +70,7 @@ enum PasscodeEntryFieldType {
var allowedCharacters: CharacterSet? {
switch self {
case .digits6, .digits4:
return CharacterSet.decimalDigits
return validDigitsSet
case .alphanumeric:
return nil
}
@ -75,7 +79,11 @@ enum PasscodeEntryFieldType {
var keyboardType: UIKeyboardType {
switch self {
case .digits6, .digits4:
if #available(iOS 10.0, *) {
return .asciiCapableNumberPad
} else {
return .numberPad
}
case .alphanumeric:
return .default
}

View File

@ -420,6 +420,9 @@ public func passcodeOptionsAccessController(context: AccountContext, animateIn:
succeed = true
case let .numericalPassword(code, _, _):
succeed = passcode == code
if !succeed {
succeed = convertToArabicNumeralString(passcode) == code
}
case let .plaintextPassword(code, _, _):
succeed = passcode == code
}

View File

@ -154,6 +154,7 @@
09EC0DE722C67FB100E7185B /* UpdateInfoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09EC0DE622C67FB100E7185B /* UpdateInfoController.swift */; };
09EC0DEB22CAFF1400E7185B /* UpdateInfoItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09EC0DEA22CAFF1400E7185B /* UpdateInfoItem.swift */; };
09EC0DED22CB583C00E7185B /* TextLinkHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09EC0DEC22CB583C00E7185B /* TextLinkHandling.swift */; };
09EC5CDC22CBD33D00292E42 /* NumberFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09EC5CDB22CBD33D00292E42 /* NumberFormat.swift */; };
09EDAD26220D30980012A50B /* AutodownloadConnectionTypeController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09EDAD25220D30980012A50B /* AutodownloadConnectionTypeController.swift */; };
09EDAD2A220DA6A40012A50B /* VolumeButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09EDAD29220DA6A40012A50B /* VolumeButtons.swift */; };
09EDAD2C2211552F0012A50B /* AutodownloadMediaCategoryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09EDAD2B2211552F0012A50B /* AutodownloadMediaCategoryController.swift */; };
@ -1376,6 +1377,7 @@
09EC0DE622C67FB100E7185B /* UpdateInfoController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateInfoController.swift; sourceTree = "<group>"; };
09EC0DEA22CAFF1400E7185B /* UpdateInfoItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateInfoItem.swift; sourceTree = "<group>"; };
09EC0DEC22CB583C00E7185B /* TextLinkHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkHandling.swift; sourceTree = "<group>"; };
09EC5CDB22CBD33D00292E42 /* NumberFormat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberFormat.swift; sourceTree = "<group>"; };
09EDAD25220D30980012A50B /* AutodownloadConnectionTypeController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutodownloadConnectionTypeController.swift; sourceTree = "<group>"; };
09EDAD29220DA6A40012A50B /* VolumeButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VolumeButtons.swift; sourceTree = "<group>"; };
09EDAD2B2211552F0012A50B /* AutodownloadMediaCategoryController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutodownloadMediaCategoryController.swift; sourceTree = "<group>"; };
@ -2975,6 +2977,7 @@
0900678E21ED8E0E00530762 /* HexColor.swift */,
0947FCAF224055990086741C /* StringHash.swift */,
09F2158C225CF5BC00AEDF6D /* Pasteboard.swift */,
09EC5CDB22CBD33D00292E42 /* NumberFormat.swift */,
);
name = Strings;
sourceTree = "<group>";
@ -6051,6 +6054,7 @@
09FFBCD9228473BD00C33B4B /* CallSuggestTabController.swift in Sources */,
D0EC6DFC1EB9F58900EBF1C3 /* GalleryController.swift in Sources */,
D0EC6DFD1EB9F58900EBF1C3 /* GalleryControllerNode.swift in Sources */,
09EC5CDC22CBD33D00292E42 /* NumberFormat.swift in Sources */,
D0E9BA571F055A0B00F079A4 /* STPFormTextField.m in Sources */,
D0EC6DFE1EB9F58900EBF1C3 /* GalleryControllerPresentationState.swift in Sources */,
D00817DB22B47A14008A895F /* LegacyChatImport.swift in Sources */,