├── .gitignore ├── LICENSE ├── Package.swift ├── PasscodeKit.podspec ├── PasscodeKit ├── Sources │ ├── PasscodeKit.swift │ ├── PasscodeKitChange.swift │ ├── PasscodeKitCreate.swift │ ├── PasscodeKitRemove.swift │ ├── PasscodeKitText.swift │ └── PasscodeKitVerify.swift ├── app.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── app │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── 0076.png │ │ ├── 0120.png │ │ ├── 0152.png │ │ ├── 0167.png │ │ ├── 0180.png │ │ ├── 1024.png │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ └── LaunchScreen.storyboard │ ├── Info.plist │ ├── NavController.swift │ ├── PasscodeView.swift │ ├── PasscodeView.xib │ ├── ViewController.swift │ └── ViewController.xib ├── README.md └── VERSION.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Related Code 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "PasscodeKit", 6 | platforms: [ 7 | .iOS(.v13), 8 | ], 9 | products: [ 10 | .library( 11 | name: "PasscodeKit", 12 | type: .static, 13 | targets: ["PasscodeKit"]), 14 | ], 15 | targets: [ 16 | .target( 17 | name: "PasscodeKit", 18 | dependencies: [], 19 | path: "./PasscodeKit", 20 | sources: ["Sources"] 21 | ), 22 | ] 23 | ) 24 | -------------------------------------------------------------------------------- /PasscodeKit.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'PasscodeKit' 3 | s.version = '1.0.4' 4 | s.license = 'MIT' 5 | 6 | s.summary = 'A lightweight and easy-to-use Passcode Kit for iOS.' 7 | s.homepage = 'https://relatedcode.com' 8 | s.author = { 'Related Code' => 'info@relatedcode.com' } 9 | 10 | s.source = { :git => 'https://github.com/relatedcode/PasscodeKit.git', :tag => s.version } 11 | s.source_files = 'PasscodeKit/Sources/*.swift' 12 | 13 | s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.0' } 14 | 15 | s.swift_version = '5.0' 16 | s.platform = :ios, '12.0' 17 | s.requires_arc = true 18 | end 19 | -------------------------------------------------------------------------------- /PasscodeKit/Sources/PasscodeKit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | import CryptoKit 14 | 15 | // MARK: - PasscodeKitDelegate 16 | @objc public protocol PasscodeKitDelegate { 17 | 18 | @objc optional func passcodeCreated(_ passcode: String) 19 | @objc optional func passcodeChanged(_ passcode: String) 20 | @objc optional func passcodeRemoved() 21 | 22 | @objc optional func passcodeCheckedButDisabled() 23 | @objc optional func passcodeEnteredSuccessfully() 24 | @objc optional func passcodeMaximumFailedAttempts() 25 | } 26 | 27 | // MARK: - PasscodeKit 28 | public class PasscodeKit: NSObject { 29 | static let shared: PasscodeKit = { 30 | let instance = PasscodeKit() 31 | return instance 32 | }() 33 | 34 | public static var passcodeLength = 4 35 | public static var allowedFailedAttempts = 3 36 | 37 | public static var textColor = UIColor.darkText 38 | public static var backgroundColor = UIColor.lightGray 39 | 40 | public static var failedTextColor = UIColor.white 41 | public static var failedBackgroundColor = UIColor.systemRed 42 | 43 | public static var titleEnterPasscode = "Enter Passcode" 44 | public static var titleCreatePasscode = "Create Passcode" 45 | public static var titleChangePasscode = "Change Passcode" 46 | public static var titleRemovePasscode = "Remove Passcode" 47 | 48 | public static var textEnterPasscode = "Enter your passcode" 49 | public static var textVerifyPasscode = "Verify your passcode" 50 | public static var textEnterOldPasscode = "Enter your old passcode" 51 | public static var textEnterNewPasscode = "Enter your new passcode" 52 | public static var textVerifyNewPasscode = "Verify your new passcode" 53 | public static var textFailedPasscode = "%d Failed Passcode Attempts" 54 | public static var textPasscodeMismatch = "Passcodes did not match. Try again." 55 | public static var textTouchIDAccessReason = "Please use Touch ID to unlock the app" 56 | 57 | public static var delegate: PasscodeKitDelegate? 58 | 59 | public override init() { 60 | super.init() 61 | 62 | if #available(iOS 13.0, *) { 63 | PasscodeKit.textColor = UIColor.label 64 | PasscodeKit.backgroundColor = UIColor.systemGroupedBackground 65 | } else { 66 | PasscodeKit.backgroundColor = UIColor.groupTableViewBackground 67 | } 68 | } 69 | 70 | public class func start() { 71 | shared.start() 72 | } 73 | 74 | public class func dismiss() { 75 | if (PasscodeKit.enabled()) { 76 | if let navigationController = shared.topViewController() as? UINavigationController { 77 | if let presentedView = navigationController.viewControllers.first { 78 | if (presentedView is PasscodeKitVerify) { 79 | presentedView.dismiss(animated: true) 80 | } 81 | } 82 | } 83 | } 84 | } 85 | } 86 | 87 | // MARK: - 88 | extension PasscodeKit { 89 | 90 | private func start() { 91 | let didFinishLaunching = UIApplication.didFinishLaunchingNotification 92 | let willEnterForeground = UIApplication.willEnterForegroundNotification 93 | 94 | NotificationCenter.default.addObserver(self, selector: #selector(verifyPasscode), name: didFinishLaunching, object: nil) 95 | NotificationCenter.default.addObserver(self, selector: #selector(verifyPasscode), name: willEnterForeground, object: nil) 96 | } 97 | 98 | @objc private func verifyPasscode() { 99 | if (PasscodeKit.enabled()) { 100 | if let viewController = topViewController() { 101 | if (noPasscodePresented(viewController)) { 102 | presentPasscodeVerify(viewController) 103 | } 104 | } 105 | } else { 106 | PasscodeKit.delegate?.passcodeCheckedButDisabled?() 107 | } 108 | } 109 | 110 | private func presentPasscodeVerify(_ viewController: UIViewController) { 111 | DispatchQueue.main.async { 112 | let passcodeKitVerify = PasscodeKitVerify() 113 | passcodeKitVerify.delegate = PasscodeKit.delegate 114 | let navController = PasscodeKitNavController(rootViewController: passcodeKitVerify) 115 | viewController.present(navController, animated: false) 116 | } 117 | } 118 | 119 | private func noPasscodePresented(_ viewController: UIViewController) -> Bool { 120 | var result = true 121 | if let navigationController = viewController as? UINavigationController { 122 | if let presentedView = navigationController.viewControllers.first { 123 | if (presentedView is PasscodeKitCreate) { result = false } 124 | if (presentedView is PasscodeKitChange) { result = false } 125 | if (presentedView is PasscodeKitRemove) { result = false } 126 | if (presentedView is PasscodeKitVerify) { result = false } 127 | } 128 | } 129 | return result 130 | } 131 | 132 | private func topViewController() -> UIViewController? { 133 | var keyWindow: UIWindow? 134 | 135 | if #available(iOS 13.0, *) { 136 | keyWindow = UIApplication.shared.windows.first { $0.isKeyWindow } 137 | } else { 138 | keyWindow = UIApplication.shared.keyWindow 139 | } 140 | 141 | var viewController = keyWindow?.rootViewController 142 | while (viewController?.presentedViewController != nil) { 143 | viewController = viewController?.presentedViewController 144 | } 145 | return viewController 146 | } 147 | } 148 | 149 | // MARK: - 150 | extension PasscodeKit { 151 | 152 | public class func createPasscode(_ viewController: UIViewController) { 153 | let passcodeKitCreate = PasscodeKitCreate() 154 | passcodeKitCreate.delegate = viewController as? PasscodeKitDelegate 155 | let navController = PasscodeKitNavController(rootViewController: passcodeKitCreate) 156 | viewController.present(navController, animated: true) 157 | } 158 | 159 | public class func changePasscode(_ viewController: UIViewController) { 160 | let passcodeKitChange = PasscodeKitChange() 161 | passcodeKitChange.delegate = viewController as? PasscodeKitDelegate 162 | let navController = PasscodeKitNavController(rootViewController: passcodeKitChange) 163 | viewController.present(navController, animated: true) 164 | } 165 | 166 | public class func removePasscode(_ viewController: UIViewController) { 167 | let passcodeKitRemove = PasscodeKitRemove() 168 | passcodeKitRemove.delegate = viewController as? PasscodeKitDelegate 169 | let navController = PasscodeKitNavController(rootViewController: passcodeKitRemove) 170 | viewController.present(navController, animated: true) 171 | } 172 | } 173 | 174 | // MARK: - 175 | extension PasscodeKit { 176 | 177 | public class func enabled() -> Bool { 178 | return (UserDefaults.standard.string(forKey: "PasscodeValue") != nil) 179 | } 180 | 181 | public class func verify(_ passcode: String) -> Bool { 182 | if (passcode != "") { 183 | return (UserDefaults.standard.string(forKey: "PasscodeValue") == sha256(passcode)) 184 | } 185 | return (UserDefaults.standard.string(forKey: "PasscodeValue") == nil) 186 | } 187 | 188 | public class func update(_ passcode: String) { 189 | if (passcode != "") { 190 | UserDefaults.standard.set(sha256(passcode), forKey: "PasscodeValue") 191 | } else { 192 | UserDefaults.standard.removeObject(forKey: "PasscodeValue") 193 | UserDefaults.standard.removeObject(forKey: "PasscodeBiometric") 194 | } 195 | } 196 | 197 | public class func remove() { 198 | UserDefaults.standard.removeObject(forKey: "PasscodeValue") 199 | UserDefaults.standard.removeObject(forKey: "PasscodeBiometric") 200 | } 201 | 202 | public class func biometric() -> Bool { 203 | return UserDefaults.standard.bool(forKey: "PasscodeBiometric") 204 | } 205 | 206 | public class func biometric(_ value: Bool) { 207 | UserDefaults.standard.set(value, forKey: "PasscodeBiometric") 208 | } 209 | 210 | private class func sha256(_ text: String) -> String { 211 | if #available(iOS 13.0, *) { 212 | let data = Data(text.utf8) 213 | let hash = SHA256.hash(data: data) 214 | return hash.compactMap { String(format: "%02x", $0) }.joined() 215 | } 216 | return text 217 | } 218 | } 219 | 220 | // MARK: - PasscodeKitNavController 221 | class PasscodeKitNavController: UINavigationController { 222 | 223 | override func viewDidLoad() { 224 | super.viewDidLoad() 225 | 226 | if #available(iOS 13.0, *) { 227 | self.isModalInPresentation = true 228 | self.modalPresentationStyle = .fullScreen 229 | } 230 | 231 | navigationBar.isTranslucent = false 232 | } 233 | 234 | override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 235 | return .portrait 236 | } 237 | 238 | override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { 239 | return .portrait 240 | } 241 | 242 | override var shouldAutorotate: Bool { 243 | return false 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /PasscodeKit/Sources/PasscodeKitChange.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | 14 | // MARK: - PasscodeState 15 | private enum PasscodeState { 16 | 17 | case change1 18 | case change2 19 | case change3 20 | case complete 21 | } 22 | 23 | // MARK: - PasscodeKitChange 24 | class PasscodeKitChange: UIViewController { 25 | 26 | private var state: PasscodeState! 27 | private var passcode = "" 28 | 29 | private var failedAttempts = 0 30 | private var isPasscodeMismatch = false 31 | 32 | private var viewPasscode = UIView() 33 | private var textPasscode: PasscodeKitText! 34 | private var labelInfo = UILabel() 35 | private var labelPasscodeMismatch = UILabel() 36 | private var labelFailedAttempts = UILabel() 37 | 38 | var delegate: PasscodeKitDelegate? 39 | 40 | override func viewDidLoad() { 41 | super.viewDidLoad() 42 | 43 | title = PasscodeKit.titleChangePasscode 44 | 45 | navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(actionCancel)) 46 | 47 | setupUI() 48 | updateUI() 49 | } 50 | 51 | override func viewDidAppear(_ animated: Bool) { 52 | super.viewDidAppear(animated) 53 | 54 | textPasscode.becomeFirstResponder() 55 | } 56 | 57 | @objc private func actionCancel() { 58 | dismiss(animated: true) 59 | } 60 | } 61 | 62 | // MARK: - 63 | extension PasscodeKitChange { 64 | 65 | private func setupUI() { 66 | state = .change1 67 | 68 | view.backgroundColor = PasscodeKit.backgroundColor 69 | 70 | viewPasscode.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 120) 71 | view.addSubview(viewPasscode) 72 | 73 | labelInfo.textAlignment = .center 74 | labelInfo.textColor = PasscodeKit.textColor 75 | labelInfo.font = UIFont.systemFont(ofSize: 17) 76 | labelInfo.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 30) 77 | viewPasscode.addSubview(labelInfo) 78 | 79 | if (textPasscode != nil) && (textPasscode.superview != nil) { 80 | textPasscode.removeFromSuperview() 81 | } 82 | textPasscode = PasscodeKitText() 83 | textPasscode.frame = CGRect(x: 0, y: 45, width: UIScreen.main.bounds.width, height: 30) 84 | textPasscode.addTarget(self, action: #selector(textFieldDidChangeEditing(_:)), for: .editingChanged) 85 | viewPasscode.addSubview(textPasscode) 86 | 87 | labelPasscodeMismatch.text = PasscodeKit.textPasscodeMismatch 88 | labelPasscodeMismatch.textAlignment = .center 89 | labelPasscodeMismatch.textColor = PasscodeKit.textColor 90 | labelPasscodeMismatch.font = UIFont.systemFont(ofSize: 15) 91 | labelPasscodeMismatch.frame = CGRect(x: 0, y: 90, width: UIScreen.main.bounds.width, height: 30) 92 | labelPasscodeMismatch.isHidden = true 93 | viewPasscode.addSubview(labelPasscodeMismatch) 94 | 95 | labelFailedAttempts.textAlignment = .center 96 | labelFailedAttempts.textColor = PasscodeKit.failedTextColor 97 | labelFailedAttempts.backgroundColor = PasscodeKit.failedBackgroundColor 98 | labelFailedAttempts.font = UIFont.systemFont(ofSize: 15) 99 | labelFailedAttempts.frame = CGRect(x: (UIScreen.main.bounds.width - 225) / 2, y: 90, width: 225, height: 30) 100 | labelFailedAttempts.layer.cornerRadius = 15 101 | labelFailedAttempts.isHidden = true 102 | labelFailedAttempts.clipsToBounds = true 103 | viewPasscode.addSubview(labelFailedAttempts) 104 | } 105 | 106 | private func updateUI() { 107 | if (state == .change1) { labelInfo.text = PasscodeKit.textEnterOldPasscode } 108 | if (state == .change2) { labelInfo.text = PasscodeKit.textEnterNewPasscode } 109 | if (state == .change3) { labelInfo.text = PasscodeKit.textVerifyNewPasscode } 110 | 111 | if (state == .change3) { 112 | isPasscodeMismatch = false 113 | } 114 | 115 | failedAttempts = 0 116 | textPasscode.text = "" 117 | textPasscode.becomeFirstResponder() 118 | labelPasscodeMismatch.isHidden = !isPasscodeMismatch 119 | labelFailedAttempts.isHidden = true 120 | animateViewPasscode() 121 | } 122 | 123 | private func animateViewPasscode() { 124 | let originalXPos = viewPasscode.frame.origin.x 125 | viewPasscode.frame.origin.x = originalXPos + (isPasscodeMismatch ? -250 : 250) 126 | UIView.animate(withDuration: 0.15) { 127 | self.viewPasscode.frame.origin.x = originalXPos 128 | } 129 | } 130 | 131 | private func setupUIFailed() { 132 | let animation = CABasicAnimation(keyPath: "position") 133 | animation.duration = 0.09 134 | animation.repeatCount = 2 135 | animation.isRemovedOnCompletion = true 136 | animation.autoreverses = true 137 | animation.fromValue = CGPoint(x: textPasscode.center.x - 10, y: textPasscode.center.y) 138 | animation.toValue = CGPoint(x: textPasscode.center.x + 10, y: textPasscode.center.y) 139 | textPasscode.layer.add(animation, forKey: "position") 140 | 141 | failedAttempts += 1 142 | labelFailedAttempts.isHidden = false 143 | labelFailedAttempts.text = String(format: PasscodeKit.textFailedPasscode, failedAttempts) 144 | 145 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { 146 | self.textPasscode.text = "" 147 | } 148 | 149 | if (failedAttempts >= PasscodeKit.allowedFailedAttempts) { 150 | delegate?.passcodeMaximumFailedAttempts?() 151 | } 152 | } 153 | } 154 | 155 | // MARK: - 156 | extension PasscodeKitChange { 157 | 158 | @objc private func textFieldDidChangeEditing(_ textField: UITextField) { 159 | let current = textField.text ?? "" 160 | 161 | if (current.count >= PasscodeKit.passcodeLength) { 162 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 163 | self.actionPasscode(current) 164 | } 165 | } 166 | } 167 | 168 | private func actionPasscode(_ current: String) { 169 | if (state == .change1) { 170 | actionVerify(current) 171 | } else if (state == .change2) { 172 | actionChange(current) 173 | } else if (state == .change3) { 174 | actionConfirm(current) 175 | } 176 | } 177 | 178 | private func actionVerify(_ current: String) { 179 | if (PasscodeKit.verify(current)) { 180 | state = .change2 181 | updateUI() 182 | } else { 183 | setupUIFailed() 184 | } 185 | } 186 | 187 | private func actionChange(_ current: String) { 188 | state = .change3 189 | passcode = current 190 | updateUI() 191 | } 192 | 193 | private func actionConfirm(_ current: String) { 194 | if (passcode == current) { 195 | PasscodeKit.update(passcode) 196 | delegate?.passcodeChanged?(passcode) 197 | dismiss(animated: true) 198 | } else { 199 | isPasscodeMismatch = true 200 | state = .change2 201 | updateUI() 202 | } 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /PasscodeKit/Sources/PasscodeKitCreate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | 14 | // MARK: - PasscodeKitCreate 15 | class PasscodeKitCreate: UIViewController { 16 | 17 | private var passcode = "" 18 | private var isPasscodeMismatch = false 19 | 20 | private var viewPasscode = UIView() 21 | private var textPasscode: PasscodeKitText! 22 | private var labelInfo = UILabel() 23 | private var labelPasscodeMismatch = UILabel() 24 | 25 | var delegate: PasscodeKitDelegate? 26 | 27 | override func viewDidLoad() { 28 | super.viewDidLoad() 29 | 30 | title = PasscodeKit.titleCreatePasscode 31 | 32 | navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(actionCancel)) 33 | 34 | setupUI() 35 | updateUI() 36 | } 37 | 38 | override func viewDidAppear(_ animated: Bool) { 39 | super.viewDidAppear(animated) 40 | textPasscode.becomeFirstResponder() 41 | } 42 | 43 | @objc private func actionCancel() { 44 | dismiss(animated: true) 45 | } 46 | } 47 | 48 | // MARK: - 49 | extension PasscodeKitCreate { 50 | 51 | private func setupUI() { 52 | view.backgroundColor = PasscodeKit.backgroundColor 53 | 54 | viewPasscode.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 120) 55 | view.addSubview(viewPasscode) 56 | 57 | labelInfo.textAlignment = .center 58 | labelInfo.textColor = PasscodeKit.textColor 59 | labelInfo.font = UIFont.systemFont(ofSize: 17) 60 | labelInfo.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 30) 61 | viewPasscode.addSubview(labelInfo) 62 | 63 | if (textPasscode != nil) && (textPasscode.superview != nil) { 64 | textPasscode.removeFromSuperview() 65 | } 66 | textPasscode = PasscodeKitText() 67 | textPasscode.frame = CGRect(x: 0, y: 45, width: UIScreen.main.bounds.width, height: 30) 68 | textPasscode.addTarget(self, action: #selector(textFieldDidChangeEditing(_:)), for: .editingChanged) 69 | viewPasscode.addSubview(textPasscode) 70 | 71 | labelPasscodeMismatch.text = PasscodeKit.textPasscodeMismatch 72 | labelPasscodeMismatch.textAlignment = .center 73 | labelPasscodeMismatch.textColor = PasscodeKit.textColor 74 | labelPasscodeMismatch.font = UIFont.systemFont(ofSize: 15) 75 | labelPasscodeMismatch.frame = CGRect(x: 0, y: 90, width: UIScreen.main.bounds.width, height: 30) 76 | labelPasscodeMismatch.isHidden = true 77 | viewPasscode.addSubview(labelPasscodeMismatch) 78 | } 79 | 80 | private func updateUI() { 81 | if (passcode == "") { 82 | labelInfo.text = PasscodeKit.textEnterPasscode 83 | } else { 84 | labelInfo.text = PasscodeKit.textVerifyPasscode 85 | isPasscodeMismatch = false 86 | } 87 | 88 | textPasscode.text = "" 89 | textPasscode.becomeFirstResponder() 90 | labelPasscodeMismatch.isHidden = !isPasscodeMismatch 91 | animateViewPasscode() 92 | } 93 | 94 | private func animateViewPasscode() { 95 | let originalXPos = viewPasscode.frame.origin.x 96 | viewPasscode.frame.origin.x = originalXPos + (isPasscodeMismatch ? -250 : 250) 97 | UIView.animate(withDuration: 0.15) { 98 | self.viewPasscode.frame.origin.x = originalXPos 99 | } 100 | } 101 | } 102 | 103 | // MARK: - 104 | extension PasscodeKitCreate { 105 | 106 | @objc private func textFieldDidChangeEditing(_ textField: UITextField) { 107 | let current = textField.text ?? "" 108 | 109 | if (current.count >= PasscodeKit.passcodeLength) { 110 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 111 | self.actionPasscode(current) 112 | } 113 | } 114 | } 115 | 116 | private func actionPasscode(_ current: String) { 117 | if (passcode == "") { 118 | passcode = current 119 | updateUI() 120 | } else { 121 | if (passcode == current) { 122 | PasscodeKit.update(passcode) 123 | delegate?.passcodeCreated?(passcode) 124 | dismiss(animated: true) 125 | } else { 126 | isPasscodeMismatch = true 127 | passcode = "" 128 | updateUI() 129 | } 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /PasscodeKit/Sources/PasscodeKitRemove.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | 14 | // MARK: - PasscodeKitRemove 15 | class PasscodeKitRemove: UIViewController { 16 | 17 | private var failedAttempts = 0 18 | 19 | private var viewPasscode = UIView() 20 | private var textPasscode: PasscodeKitText! 21 | private var labelInfo = UILabel() 22 | private var labelFailedAttempts = UILabel() 23 | 24 | var delegate: PasscodeKitDelegate? 25 | 26 | override func viewDidLoad() { 27 | super.viewDidLoad() 28 | 29 | title = PasscodeKit.titleRemovePasscode 30 | 31 | navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(actionCancel)) 32 | 33 | setupUI() 34 | updateUI() 35 | } 36 | 37 | override func viewDidAppear(_ animated: Bool) { 38 | super.viewDidAppear(animated) 39 | textPasscode.becomeFirstResponder() 40 | } 41 | 42 | @objc private func actionCancel() { 43 | dismiss(animated: true) 44 | } 45 | } 46 | 47 | // MARK: - 48 | extension PasscodeKitRemove { 49 | 50 | private func setupUI() { 51 | view.backgroundColor = PasscodeKit.backgroundColor 52 | 53 | viewPasscode.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 120) 54 | view.addSubview(viewPasscode) 55 | 56 | labelInfo.textAlignment = .center 57 | labelInfo.textColor = PasscodeKit.textColor 58 | labelInfo.font = UIFont.systemFont(ofSize: 17) 59 | labelInfo.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 30) 60 | viewPasscode.addSubview(labelInfo) 61 | 62 | if (textPasscode != nil) && (textPasscode.superview != nil) { 63 | textPasscode.removeFromSuperview() 64 | } 65 | textPasscode = PasscodeKitText() 66 | textPasscode.frame = CGRect(x: 0, y: 45, width: UIScreen.main.bounds.width, height: 30) 67 | textPasscode.addTarget(self, action: #selector(textFieldDidChangeEditing(_:)), for: .editingChanged) 68 | viewPasscode.addSubview(textPasscode) 69 | 70 | labelFailedAttempts.textAlignment = .center 71 | labelFailedAttempts.textColor = PasscodeKit.failedTextColor 72 | labelFailedAttempts.backgroundColor = PasscodeKit.failedBackgroundColor 73 | labelFailedAttempts.font = UIFont.systemFont(ofSize: 15) 74 | labelFailedAttempts.frame = CGRect(x: (UIScreen.main.bounds.width - 225) / 2, y: 90, width: 225, height: 30) 75 | labelFailedAttempts.layer.cornerRadius = 15 76 | labelFailedAttempts.isHidden = true 77 | labelFailedAttempts.clipsToBounds = true 78 | viewPasscode.addSubview(labelFailedAttempts) 79 | } 80 | 81 | private func updateUI() { 82 | labelInfo.text = PasscodeKit.textEnterPasscode 83 | 84 | failedAttempts = 0 85 | textPasscode.text = "" 86 | textPasscode.becomeFirstResponder() 87 | labelFailedAttempts.isHidden = true 88 | } 89 | 90 | private func setupUIFailed() { 91 | let animation = CABasicAnimation(keyPath: "position") 92 | animation.duration = 0.09 93 | animation.repeatCount = 2 94 | animation.isRemovedOnCompletion = true 95 | animation.autoreverses = true 96 | animation.fromValue = CGPoint(x: textPasscode.center.x - 10, y: textPasscode.center.y) 97 | animation.toValue = CGPoint(x: textPasscode.center.x + 10, y: textPasscode.center.y) 98 | textPasscode.layer.add(animation, forKey: "position") 99 | 100 | failedAttempts += 1 101 | labelFailedAttempts.isHidden = false 102 | labelFailedAttempts.text = String(format: PasscodeKit.textFailedPasscode, failedAttempts) 103 | 104 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { 105 | self.textPasscode.text = "" 106 | } 107 | 108 | if (failedAttempts >= PasscodeKit.allowedFailedAttempts) { 109 | delegate?.passcodeMaximumFailedAttempts?() 110 | } 111 | } 112 | } 113 | 114 | // MARK: - 115 | extension PasscodeKitRemove { 116 | 117 | @objc private func textFieldDidChangeEditing(_ textField: UITextField) { 118 | let current = textField.text ?? "" 119 | 120 | if (current.count >= PasscodeKit.passcodeLength) { 121 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 122 | self.actionPasscode(current) 123 | } 124 | } 125 | } 126 | 127 | private func actionPasscode(_ current: String) { 128 | if (PasscodeKit.verify(current)) { 129 | PasscodeKit.remove() 130 | delegate?.passcodeRemoved?() 131 | dismiss(animated: true) 132 | } else { 133 | setupUIFailed() 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /PasscodeKit/Sources/PasscodeKitText.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | 14 | // MARK: - PasscodeKitText 15 | class PasscodeKitText: UITextField { 16 | 17 | private let radius: CGFloat = 8 18 | private let spacing: CGFloat = 20 19 | 20 | override init(frame: CGRect) { 21 | super.init(frame: frame) 22 | 23 | tintColor = .clear 24 | textColor = .clear 25 | borderStyle = .none 26 | keyboardType = .numberPad 27 | textContentType = .password 28 | 29 | font = UIFont.systemFont(ofSize: 0) 30 | } 31 | 32 | required init?(coder: NSCoder) { 33 | super.init(coder: coder) 34 | } 35 | 36 | override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { 37 | return false 38 | } 39 | 40 | override func layoutSubviews() { 41 | super.layoutSubviews() 42 | 43 | layer.sublayers?.forEach { layer in 44 | if (layer.name == "PasscodeKitSublayer") { 45 | layer.removeFromSuperlayer() 46 | } 47 | } 48 | 49 | let currentLength = text?.count ?? 0 50 | let passcodeLength = PasscodeKit.passcodeLength 51 | 52 | let circles = CGFloat(passcodeLength) 53 | let layerWidth = (2 * radius * circles) + spacing * (circles - 1) 54 | let layerXPos = (frame.size.width - layerWidth) / 2 55 | let layerYPos = (frame.size.height - 2 * radius) / 2 56 | 57 | let xlayer = CALayer() 58 | xlayer.frame = CGRect(x: layerXPos, y: layerYPos, width: layerWidth, height: 2 * radius) 59 | xlayer.name = "PasscodeKitSublayer" 60 | layer.addSublayer(xlayer) 61 | 62 | let circleCenter = CGPoint(x: radius, y: radius) 63 | let circlePath = UIBezierPath(arcCenter: circleCenter, radius: radius, startAngle: 0, endAngle: 2 * .pi, clockwise: false) 64 | let circleColor = PasscodeKit.textColor.cgColor 65 | 66 | for i in 0..= PasscodeKit.allowedFailedAttempts) { 132 | delegate?.passcodeMaximumFailedAttempts?() 133 | } 134 | } 135 | } 136 | 137 | // MARK: - 138 | extension PasscodeKitVerify { 139 | 140 | @objc private func textFieldDidChangeEditing(_ textField: UITextField) { 141 | let current = textField.text ?? "" 142 | 143 | if (current.count >= PasscodeKit.passcodeLength) { 144 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 145 | self.actionPasscode(current) 146 | } 147 | } 148 | } 149 | 150 | private func actionPasscode(_ current: String) { 151 | if (PasscodeKit.verify(current)) { 152 | delegate?.passcodeEnteredSuccessfully?() 153 | dismiss(animated: true) 154 | } else { 155 | setupUIFailed() 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /PasscodeKit/app.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 54; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 295B8482248C1C5B003E8AE6 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 295B8480248C1C5B003E8AE6 /* ViewController.xib */; }; 11 | 295B8483248C1C5B003E8AE6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 295B8481248C1C5B003E8AE6 /* ViewController.swift */; }; 12 | 296568FA2AC9885E00FFEA60 /* NavController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296568F92AC9885E00FFEA60 /* NavController.swift */; }; 13 | 29D29EF91D9A59E4006CA074 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D29EF81D9A59E4006CA074 /* AppDelegate.swift */; }; 14 | 29D29F011D9A59E4006CA074 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29D29F001D9A59E4006CA074 /* Assets.xcassets */; }; 15 | 29D29F041D9A59E4006CA074 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29D29F021D9A59E4006CA074 /* LaunchScreen.storyboard */; }; 16 | 29D97807261DB37700C80DBD /* PasscodeKitText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D97801261DB37700C80DBD /* PasscodeKitText.swift */; }; 17 | 29D97808261DB37700C80DBD /* PasscodeKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D97802261DB37700C80DBD /* PasscodeKit.swift */; }; 18 | 29D97809261DB37700C80DBD /* PasscodeKitVerify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D97803261DB37700C80DBD /* PasscodeKitVerify.swift */; }; 19 | 29D9780A261DB37700C80DBD /* PasscodeKitCreate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D97804261DB37700C80DBD /* PasscodeKitCreate.swift */; }; 20 | 29D9780B261DB37700C80DBD /* PasscodeKitChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D97805261DB37700C80DBD /* PasscodeKitChange.swift */; }; 21 | 29D9780C261DB37700C80DBD /* PasscodeKitRemove.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D97806261DB37700C80DBD /* PasscodeKitRemove.swift */; }; 22 | 29D97810261DB39C00C80DBD /* PasscodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D9780E261DB39C00C80DBD /* PasscodeView.swift */; }; 23 | 29D97811261DB39C00C80DBD /* PasscodeView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 29D9780F261DB39C00C80DBD /* PasscodeView.xib */; }; 24 | /* End PBXBuildFile section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | 295B8480248C1C5B003E8AE6 /* ViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ViewController.xib; sourceTree = ""; }; 28 | 295B8481248C1C5B003E8AE6 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 29 | 296568F92AC9885E00FFEA60 /* NavController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavController.swift; sourceTree = ""; }; 30 | 29D29EF11D9A59E4006CA074 /* app.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = app.app; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 29D29EF81D9A59E4006CA074 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 32 | 29D29F001D9A59E4006CA074 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 33 | 29D29F031D9A59E4006CA074 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 34 | 29D29F051D9A59E4006CA074 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 29D97801261DB37700C80DBD /* PasscodeKitText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasscodeKitText.swift; sourceTree = ""; }; 36 | 29D97802261DB37700C80DBD /* PasscodeKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasscodeKit.swift; sourceTree = ""; }; 37 | 29D97803261DB37700C80DBD /* PasscodeKitVerify.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasscodeKitVerify.swift; sourceTree = ""; }; 38 | 29D97804261DB37700C80DBD /* PasscodeKitCreate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasscodeKitCreate.swift; sourceTree = ""; }; 39 | 29D97805261DB37700C80DBD /* PasscodeKitChange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasscodeKitChange.swift; sourceTree = ""; }; 40 | 29D97806261DB37700C80DBD /* PasscodeKitRemove.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasscodeKitRemove.swift; sourceTree = ""; }; 41 | 29D9780E261DB39C00C80DBD /* PasscodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasscodeView.swift; sourceTree = ""; }; 42 | 29D9780F261DB39C00C80DBD /* PasscodeView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PasscodeView.xib; sourceTree = ""; }; 43 | /* End PBXFileReference section */ 44 | 45 | /* Begin PBXFrameworksBuildPhase section */ 46 | 29D29EEE1D9A59E4006CA074 /* Frameworks */ = { 47 | isa = PBXFrameworksBuildPhase; 48 | buildActionMask = 2147483647; 49 | files = ( 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | 299876D9248FCB290025E297 /* Sources */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 29D97802261DB37700C80DBD /* PasscodeKit.swift */, 60 | 29D97805261DB37700C80DBD /* PasscodeKitChange.swift */, 61 | 29D97804261DB37700C80DBD /* PasscodeKitCreate.swift */, 62 | 29D97806261DB37700C80DBD /* PasscodeKitRemove.swift */, 63 | 29D97801261DB37700C80DBD /* PasscodeKitText.swift */, 64 | 29D97803261DB37700C80DBD /* PasscodeKitVerify.swift */, 65 | ); 66 | path = Sources; 67 | sourceTree = ""; 68 | }; 69 | 29D29EE81D9A59E4006CA074 = { 70 | isa = PBXGroup; 71 | children = ( 72 | 29D29EF31D9A59E4006CA074 /* app */, 73 | 299876D9248FCB290025E297 /* Sources */, 74 | 29D29EF21D9A59E4006CA074 /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | 29D29EF21D9A59E4006CA074 /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 29D29EF11D9A59E4006CA074 /* app.app */, 82 | ); 83 | name = Products; 84 | sourceTree = ""; 85 | }; 86 | 29D29EF31D9A59E4006CA074 /* app */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 29D29EF81D9A59E4006CA074 /* AppDelegate.swift */, 90 | 29D29F001D9A59E4006CA074 /* Assets.xcassets */, 91 | 29D29F051D9A59E4006CA074 /* Info.plist */, 92 | 29D29F021D9A59E4006CA074 /* LaunchScreen.storyboard */, 93 | 296568F92AC9885E00FFEA60 /* NavController.swift */, 94 | 29D9780E261DB39C00C80DBD /* PasscodeView.swift */, 95 | 29D9780F261DB39C00C80DBD /* PasscodeView.xib */, 96 | 295B8481248C1C5B003E8AE6 /* ViewController.swift */, 97 | 295B8480248C1C5B003E8AE6 /* ViewController.xib */, 98 | ); 99 | path = app; 100 | sourceTree = ""; 101 | }; 102 | /* End PBXGroup section */ 103 | 104 | /* Begin PBXNativeTarget section */ 105 | 29D29EF01D9A59E4006CA074 /* app */ = { 106 | isa = PBXNativeTarget; 107 | buildConfigurationList = 29D29F081D9A59E4006CA074 /* Build configuration list for PBXNativeTarget "app" */; 108 | buildPhases = ( 109 | 29D29EED1D9A59E4006CA074 /* Sources */, 110 | 29D29EEE1D9A59E4006CA074 /* Frameworks */, 111 | 29D29EEF1D9A59E4006CA074 /* Resources */, 112 | ); 113 | buildRules = ( 114 | ); 115 | dependencies = ( 116 | ); 117 | name = app; 118 | productName = app; 119 | productReference = 29D29EF11D9A59E4006CA074 /* app.app */; 120 | productType = "com.apple.product-type.application"; 121 | }; 122 | /* End PBXNativeTarget section */ 123 | 124 | /* Begin PBXProject section */ 125 | 29D29EE91D9A59E4006CA074 /* Project object */ = { 126 | isa = PBXProject; 127 | attributes = { 128 | BuildIndependentTargetsInParallel = YES; 129 | LastUpgradeCheck = 1500; 130 | ORGANIZATIONNAME = KZ; 131 | TargetAttributes = { 132 | 29D29EF01D9A59E4006CA074 = { 133 | CreatedOnToolsVersion = 8.0; 134 | LastSwiftMigration = 1000; 135 | ProvisioningStyle = Manual; 136 | SystemCapabilities = { 137 | com.apple.BackgroundModes = { 138 | enabled = 1; 139 | }; 140 | com.apple.Keychain = { 141 | enabled = 1; 142 | }; 143 | com.apple.Push = { 144 | enabled = 1; 145 | }; 146 | }; 147 | }; 148 | }; 149 | }; 150 | buildConfigurationList = 29D29EEC1D9A59E4006CA074 /* Build configuration list for PBXProject "app" */; 151 | compatibilityVersion = "Xcode 3.2"; 152 | developmentRegion = en; 153 | hasScannedForEncodings = 0; 154 | knownRegions = ( 155 | en, 156 | Base, 157 | ); 158 | mainGroup = 29D29EE81D9A59E4006CA074; 159 | productRefGroup = 29D29EF21D9A59E4006CA074 /* Products */; 160 | projectDirPath = ""; 161 | projectRoot = ""; 162 | targets = ( 163 | 29D29EF01D9A59E4006CA074 /* app */, 164 | ); 165 | }; 166 | /* End PBXProject section */ 167 | 168 | /* Begin PBXResourcesBuildPhase section */ 169 | 29D29EEF1D9A59E4006CA074 /* Resources */ = { 170 | isa = PBXResourcesBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | 29D29F041D9A59E4006CA074 /* LaunchScreen.storyboard in Resources */, 174 | 295B8482248C1C5B003E8AE6 /* ViewController.xib in Resources */, 175 | 29D97811261DB39C00C80DBD /* PasscodeView.xib in Resources */, 176 | 29D29F011D9A59E4006CA074 /* Assets.xcassets in Resources */, 177 | ); 178 | runOnlyForDeploymentPostprocessing = 0; 179 | }; 180 | /* End PBXResourcesBuildPhase section */ 181 | 182 | /* Begin PBXSourcesBuildPhase section */ 183 | 29D29EED1D9A59E4006CA074 /* Sources */ = { 184 | isa = PBXSourcesBuildPhase; 185 | buildActionMask = 2147483647; 186 | files = ( 187 | 29D97809261DB37700C80DBD /* PasscodeKitVerify.swift in Sources */, 188 | 295B8483248C1C5B003E8AE6 /* ViewController.swift in Sources */, 189 | 29D9780C261DB37700C80DBD /* PasscodeKitRemove.swift in Sources */, 190 | 29D97807261DB37700C80DBD /* PasscodeKitText.swift in Sources */, 191 | 29D9780B261DB37700C80DBD /* PasscodeKitChange.swift in Sources */, 192 | 296568FA2AC9885E00FFEA60 /* NavController.swift in Sources */, 193 | 29D97808261DB37700C80DBD /* PasscodeKit.swift in Sources */, 194 | 29D97810261DB39C00C80DBD /* PasscodeView.swift in Sources */, 195 | 29D9780A261DB37700C80DBD /* PasscodeKitCreate.swift in Sources */, 196 | 29D29EF91D9A59E4006CA074 /* AppDelegate.swift in Sources */, 197 | ); 198 | runOnlyForDeploymentPostprocessing = 0; 199 | }; 200 | /* End PBXSourcesBuildPhase section */ 201 | 202 | /* Begin PBXVariantGroup section */ 203 | 29D29F021D9A59E4006CA074 /* LaunchScreen.storyboard */ = { 204 | isa = PBXVariantGroup; 205 | children = ( 206 | 29D29F031D9A59E4006CA074 /* Base */, 207 | ); 208 | name = LaunchScreen.storyboard; 209 | sourceTree = ""; 210 | }; 211 | /* End PBXVariantGroup section */ 212 | 213 | /* Begin XCBuildConfiguration section */ 214 | 29D29F061D9A59E4006CA074 /* Debug */ = { 215 | isa = XCBuildConfiguration; 216 | buildSettings = { 217 | ALWAYS_SEARCH_USER_PATHS = NO; 218 | CLANG_ANALYZER_NONNULL = YES; 219 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 220 | CLANG_CXX_LIBRARY = "libc++"; 221 | CLANG_ENABLE_MODULES = YES; 222 | CLANG_ENABLE_OBJC_ARC = YES; 223 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 224 | CLANG_WARN_BOOL_CONVERSION = YES; 225 | CLANG_WARN_COMMA = YES; 226 | CLANG_WARN_CONSTANT_CONVERSION = YES; 227 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 228 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 229 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 230 | CLANG_WARN_EMPTY_BODY = YES; 231 | CLANG_WARN_ENUM_CONVERSION = YES; 232 | CLANG_WARN_INFINITE_RECURSION = YES; 233 | CLANG_WARN_INT_CONVERSION = YES; 234 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 235 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 236 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 237 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 238 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 239 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 240 | CLANG_WARN_STRICT_PROTOTYPES = YES; 241 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 242 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 243 | CLANG_WARN_UNREACHABLE_CODE = YES; 244 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 245 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 246 | COPY_PHASE_STRIP = NO; 247 | DEBUG_INFORMATION_FORMAT = dwarf; 248 | ENABLE_STRICT_OBJC_MSGSEND = YES; 249 | ENABLE_TESTABILITY = YES; 250 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 251 | GCC_C_LANGUAGE_STANDARD = gnu99; 252 | GCC_DYNAMIC_NO_PIC = NO; 253 | GCC_NO_COMMON_BLOCKS = YES; 254 | GCC_OPTIMIZATION_LEVEL = 0; 255 | GCC_PREPROCESSOR_DEFINITIONS = ( 256 | "DEBUG=1", 257 | "$(inherited)", 258 | ); 259 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 266 | MTL_ENABLE_DEBUG_INFO = YES; 267 | ONLY_ACTIVE_ARCH = YES; 268 | SDKROOT = iphoneos; 269 | SWIFT_VERSION = 5.0; 270 | }; 271 | name = Debug; 272 | }; 273 | 29D29F071D9A59E4006CA074 /* Release */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ALWAYS_SEARCH_USER_PATHS = NO; 277 | CLANG_ANALYZER_NONNULL = YES; 278 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 279 | CLANG_CXX_LIBRARY = "libc++"; 280 | CLANG_ENABLE_MODULES = YES; 281 | CLANG_ENABLE_OBJC_ARC = YES; 282 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 283 | CLANG_WARN_BOOL_CONVERSION = YES; 284 | CLANG_WARN_COMMA = YES; 285 | CLANG_WARN_CONSTANT_CONVERSION = YES; 286 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 287 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 288 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 289 | CLANG_WARN_EMPTY_BODY = YES; 290 | CLANG_WARN_ENUM_CONVERSION = YES; 291 | CLANG_WARN_INFINITE_RECURSION = YES; 292 | CLANG_WARN_INT_CONVERSION = YES; 293 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 294 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 295 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 296 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 297 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 298 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 299 | CLANG_WARN_STRICT_PROTOTYPES = YES; 300 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 301 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 302 | CLANG_WARN_UNREACHABLE_CODE = YES; 303 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 304 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 305 | COPY_PHASE_STRIP = NO; 306 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 307 | ENABLE_NS_ASSERTIONS = NO; 308 | ENABLE_STRICT_OBJC_MSGSEND = YES; 309 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 310 | GCC_C_LANGUAGE_STANDARD = gnu99; 311 | GCC_NO_COMMON_BLOCKS = YES; 312 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 313 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 314 | GCC_WARN_UNDECLARED_SELECTOR = YES; 315 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 316 | GCC_WARN_UNUSED_FUNCTION = YES; 317 | GCC_WARN_UNUSED_VARIABLE = YES; 318 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 319 | MTL_ENABLE_DEBUG_INFO = NO; 320 | SDKROOT = iphoneos; 321 | SWIFT_COMPILATION_MODE = wholemodule; 322 | SWIFT_VERSION = 5.0; 323 | VALIDATE_PRODUCT = YES; 324 | }; 325 | name = Release; 326 | }; 327 | 29D29F091D9A59E4006CA074 /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 331 | CLANG_ENABLE_MODULES = NO; 332 | CLANG_WARN_DOCUMENTATION_COMMENTS = NO; 333 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO; 334 | CODE_SIGN_ENTITLEMENTS = ""; 335 | CODE_SIGN_IDENTITY = "Apple Development"; 336 | CODE_SIGN_STYLE = Manual; 337 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 338 | DEVELOPMENT_TEAM = ""; 339 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 340 | GCC_PREFIX_HEADER = ""; 341 | INFOPLIST_FILE = app/Info.plist; 342 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 343 | LD_RUNPATH_SEARCH_PATHS = "$(inherited)"; 344 | MARKETING_VERSION = 1.0.4; 345 | PRODUCT_BUNDLE_IDENTIFIER = com.relatedcode.passcodekit; 346 | PRODUCT_NAME = "$(TARGET_NAME)"; 347 | PROVISIONING_PROFILE_SPECIFIER = ""; 348 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; 349 | SUPPORTS_MACCATALYST = NO; 350 | SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; 351 | SWIFT_INSTALL_OBJC_HEADER = NO; 352 | SWIFT_OBJC_BRIDGING_HEADER = ""; 353 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 354 | SWIFT_PRECOMPILE_BRIDGING_HEADER = NO; 355 | SWIFT_SUPPRESS_WARNINGS = NO; 356 | SWIFT_VERSION = 5.0; 357 | TARGETED_DEVICE_FAMILY = 1; 358 | }; 359 | name = Debug; 360 | }; 361 | 29D29F0A1D9A59E4006CA074 /* Release */ = { 362 | isa = XCBuildConfiguration; 363 | buildSettings = { 364 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 365 | CLANG_ENABLE_MODULES = NO; 366 | CLANG_WARN_DOCUMENTATION_COMMENTS = NO; 367 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO; 368 | CODE_SIGN_ENTITLEMENTS = ""; 369 | CODE_SIGN_IDENTITY = "Apple Development"; 370 | CODE_SIGN_STYLE = Manual; 371 | DEVELOPMENT_TEAM = ""; 372 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 373 | GCC_PREFIX_HEADER = ""; 374 | INFOPLIST_FILE = app/Info.plist; 375 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 376 | LD_RUNPATH_SEARCH_PATHS = "$(inherited)"; 377 | MARKETING_VERSION = 1.0.4; 378 | PRODUCT_BUNDLE_IDENTIFIER = com.relatedcode.passcodekit; 379 | PRODUCT_NAME = "$(TARGET_NAME)"; 380 | PROVISIONING_PROFILE_SPECIFIER = ""; 381 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; 382 | SUPPORTS_MACCATALYST = NO; 383 | SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; 384 | SWIFT_INSTALL_OBJC_HEADER = NO; 385 | SWIFT_OBJC_BRIDGING_HEADER = ""; 386 | SWIFT_PRECOMPILE_BRIDGING_HEADER = NO; 387 | SWIFT_VERSION = 5.0; 388 | TARGETED_DEVICE_FAMILY = 1; 389 | }; 390 | name = Release; 391 | }; 392 | /* End XCBuildConfiguration section */ 393 | 394 | /* Begin XCConfigurationList section */ 395 | 29D29EEC1D9A59E4006CA074 /* Build configuration list for PBXProject "app" */ = { 396 | isa = XCConfigurationList; 397 | buildConfigurations = ( 398 | 29D29F061D9A59E4006CA074 /* Debug */, 399 | 29D29F071D9A59E4006CA074 /* Release */, 400 | ); 401 | defaultConfigurationIsVisible = 0; 402 | defaultConfigurationName = Release; 403 | }; 404 | 29D29F081D9A59E4006CA074 /* Build configuration list for PBXNativeTarget "app" */ = { 405 | isa = XCConfigurationList; 406 | buildConfigurations = ( 407 | 29D29F091D9A59E4006CA074 /* Debug */, 408 | 29D29F0A1D9A59E4006CA074 /* Release */, 409 | ); 410 | defaultConfigurationIsVisible = 0; 411 | defaultConfigurationName = Release; 412 | }; 413 | /* End XCConfigurationList section */ 414 | }; 415 | rootObject = 29D29EE91D9A59E4006CA074 /* Project object */; 416 | } 417 | -------------------------------------------------------------------------------- /PasscodeKit/app.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PasscodeKit/app.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PasscodeKit/app/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | 14 | @UIApplicationMain 15 | class AppDelegate: UIResponder, UIApplicationDelegate { 16 | 17 | var window: UIWindow? 18 | 19 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { 20 | PasscodeKit.delegate = self 21 | PasscodeKit.start() 22 | 23 | window = UIWindow(frame: UIScreen.main.bounds) 24 | 25 | let viewController = ViewController(nibName: "ViewController", bundle: nil) 26 | let navController = NavigationController(rootViewController: viewController) 27 | 28 | window?.rootViewController = navController 29 | window?.makeKeyAndVisible() 30 | 31 | return true 32 | } 33 | } 34 | 35 | // MARK: - PasscodeKitDelegate 36 | extension AppDelegate: PasscodeKitDelegate { 37 | 38 | func passcodeCheckedButDisabled() { 39 | print(#function) 40 | } 41 | 42 | func passcodeEnteredSuccessfully() { 43 | print(#function) 44 | } 45 | 46 | func passcodeMaximumFailedAttempts() { 47 | print(#function) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0076.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/relatedcode/PasscodeKit/e7b1a7916c7d7e084391a4bf1cf2c3edf93c5e6c/PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0076.png -------------------------------------------------------------------------------- /PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/relatedcode/PasscodeKit/e7b1a7916c7d7e084391a4bf1cf2c3edf93c5e6c/PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0120.png -------------------------------------------------------------------------------- /PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/relatedcode/PasscodeKit/e7b1a7916c7d7e084391a4bf1cf2c3edf93c5e6c/PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0152.png -------------------------------------------------------------------------------- /PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0167.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/relatedcode/PasscodeKit/e7b1a7916c7d7e084391a4bf1cf2c3edf93c5e6c/PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0167.png -------------------------------------------------------------------------------- /PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/relatedcode/PasscodeKit/e7b1a7916c7d7e084391a4bf1cf2c3edf93c5e6c/PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/0180.png -------------------------------------------------------------------------------- /PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/relatedcode/PasscodeKit/e7b1a7916c7d7e084391a4bf1cf2c3edf93c5e6c/PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/1024.png -------------------------------------------------------------------------------- /PasscodeKit/app/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "filename" : "0120.png", 35 | "idiom" : "iphone", 36 | "scale" : "2x", 37 | "size" : "60x60" 38 | }, 39 | { 40 | "filename" : "0180.png", 41 | "idiom" : "iphone", 42 | "scale" : "3x", 43 | "size" : "60x60" 44 | }, 45 | { 46 | "idiom" : "ipad", 47 | "scale" : "1x", 48 | "size" : "20x20" 49 | }, 50 | { 51 | "idiom" : "ipad", 52 | "scale" : "2x", 53 | "size" : "20x20" 54 | }, 55 | { 56 | "idiom" : "ipad", 57 | "scale" : "1x", 58 | "size" : "29x29" 59 | }, 60 | { 61 | "idiom" : "ipad", 62 | "scale" : "2x", 63 | "size" : "29x29" 64 | }, 65 | { 66 | "idiom" : "ipad", 67 | "scale" : "1x", 68 | "size" : "40x40" 69 | }, 70 | { 71 | "idiom" : "ipad", 72 | "scale" : "2x", 73 | "size" : "40x40" 74 | }, 75 | { 76 | "filename" : "0076.png", 77 | "idiom" : "ipad", 78 | "scale" : "1x", 79 | "size" : "76x76" 80 | }, 81 | { 82 | "filename" : "0152.png", 83 | "idiom" : "ipad", 84 | "scale" : "2x", 85 | "size" : "76x76" 86 | }, 87 | { 88 | "filename" : "0167.png", 89 | "idiom" : "ipad", 90 | "scale" : "2x", 91 | "size" : "83.5x83.5" 92 | }, 93 | { 94 | "filename" : "1024.png", 95 | "idiom" : "ios-marketing", 96 | "scale" : "1x", 97 | "size" : "1024x1024" 98 | } 99 | ], 100 | "info" : { 101 | "author" : "xcode", 102 | "version" : 1 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /PasscodeKit/app/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /PasscodeKit/app/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /PasscodeKit/app/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | PasscodeKit 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | NSFaceIDUsageDescription 32 | We use Face ID to unlock the app. 33 | UIStatusBarStyle 34 | UIStatusBarStyleLightContent 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | UIInterfaceOrientationPortraitUpsideDown 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /PasscodeKit/app/NavController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | 14 | class NavigationController: UINavigationController { 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | isModalInPresentation = true 20 | modalPresentationStyle = .fullScreen 21 | 22 | navigationBar.isTranslucent = true 23 | 24 | navigationBar.tintColor = .white 25 | navigationBar.barTintColor = .lightGray 26 | navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] 27 | 28 | if #available(iOS 15, *) { 29 | let appearance = UINavigationBarAppearance() 30 | appearance.configureWithOpaqueBackground() 31 | appearance.backgroundColor = .lightGray 32 | appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] 33 | UINavigationBar.appearance().standardAppearance = appearance 34 | UINavigationBar.appearance().scrollEdgeAppearance = appearance 35 | } 36 | } 37 | 38 | override var preferredStatusBarStyle: UIStatusBarStyle { 39 | return .lightContent 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /PasscodeKit/app/PasscodeView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | 14 | class PasscodeView: UIViewController { 15 | 16 | @IBOutlet private var tableView: UITableView! 17 | 18 | @IBOutlet private var cellTurnPasscode: UITableViewCell! 19 | @IBOutlet private var cellChangePasscode: UITableViewCell! 20 | @IBOutlet private var cellBiometric: UITableViewCell! 21 | 22 | @IBOutlet private var switchBiometric: UISwitch! 23 | 24 | override func viewDidLoad() { 25 | super.viewDidLoad() 26 | title = "Passcode" 27 | 28 | switchBiometric.addTarget(self, action: #selector(actionBiometric), for: .valueChanged) 29 | } 30 | 31 | override func viewWillAppear(_ animated: Bool) { 32 | super.viewWillAppear(animated) 33 | 34 | updateViewDetails() 35 | } 36 | } 37 | 38 | // MARK: - User actions 39 | extension PasscodeView { 40 | 41 | func actionTurnPasscode() { 42 | if (PasscodeKit.enabled()) { 43 | PasscodeKit.removePasscode(self) 44 | } else { 45 | PasscodeKit.createPasscode(self) 46 | } 47 | } 48 | 49 | func actionChangePasscode() { 50 | if (PasscodeKit.enabled()) { 51 | PasscodeKit.changePasscode(self) 52 | } 53 | } 54 | 55 | @objc func actionBiometric() { 56 | PasscodeKit.biometric(switchBiometric.isOn) 57 | } 58 | } 59 | 60 | // MARK: - Helper methods 61 | extension PasscodeView { 62 | 63 | func updateViewDetails() { 64 | if (PasscodeKit.enabled()) { 65 | cellTurnPasscode.textLabel?.text = "Turn Passcode Off" 66 | cellChangePasscode.textLabel?.textColor = UIColor.systemBlue 67 | } else { 68 | cellTurnPasscode.textLabel?.text = "Turn Passcode On" 69 | cellChangePasscode.textLabel?.textColor = UIColor.lightGray 70 | } 71 | 72 | switchBiometric.isOn = PasscodeKit.biometric() 73 | 74 | tableView.reloadData() 75 | } 76 | } 77 | 78 | // MARK: - UITableViewDataSource 79 | extension PasscodeView: UITableViewDataSource { 80 | 81 | func numberOfSections(in tableView: UITableView) -> Int { 82 | return PasscodeKit.enabled() ? 2 : 1 83 | } 84 | 85 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 86 | if (section == 0) { return 2 } 87 | if (section == 1) { return 1 } 88 | 89 | return 0 90 | } 91 | 92 | func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { 93 | if (section == 1) { return "Allow to use Face ID (or Touch ID) to unlock the app." } 94 | 95 | return nil 96 | } 97 | 98 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 99 | if (indexPath.section == 0) && (indexPath.row == 0) { return cellTurnPasscode } 100 | if (indexPath.section == 0) && (indexPath.row == 1) { return cellChangePasscode } 101 | if (indexPath.section == 1) && (indexPath.row == 0) { return cellBiometric } 102 | 103 | return UITableViewCell() 104 | } 105 | } 106 | 107 | // MARK: - UITableViewDelegate 108 | extension PasscodeView: UITableViewDelegate { 109 | 110 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 111 | tableView.deselectRow(at: indexPath, animated: true) 112 | 113 | if (indexPath.section == 0) && (indexPath.row == 0) { actionTurnPasscode() } 114 | if (indexPath.section == 0) && (indexPath.row == 1) { actionChangePasscode() } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /PasscodeKit/app/PasscodeView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /PasscodeKit/app/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Related Code - https://relatedcode.com 3 | // 4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 7 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 10 | // THE SOFTWARE. 11 | 12 | import UIKit 13 | 14 | class ViewController: UITableViewController { 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | title = "PasscodeKit" 19 | 20 | navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: nil, action: nil) 21 | } 22 | 23 | override func viewWillAppear(_ animated: Bool) { 24 | super.viewWillAppear(animated) 25 | 26 | tableView.reloadData() 27 | } 28 | } 29 | 30 | // MARK: - UITableViewDataSource 31 | extension ViewController { 32 | 33 | override func numberOfSections(in tableView: UITableView) -> Int { 34 | return 1 35 | } 36 | 37 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 38 | return 1 39 | } 40 | 41 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 42 | var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: "cell") 43 | if (cell == nil) { cell = UITableViewCell(style: .value1, reuseIdentifier: "cell") } 44 | 45 | cell.textLabel?.text = "Passcode Lock" 46 | cell.detailTextLabel?.text = PasscodeKit.enabled() ? "On" : "Off" 47 | cell.accessoryType = .disclosureIndicator 48 | 49 | return cell 50 | } 51 | } 52 | 53 | // MARK: - UITableViewDelegate 54 | extension ViewController { 55 | 56 | override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 57 | tableView.deselectRow(at: indexPath, animated: true) 58 | 59 | let passcodeView = PasscodeView() 60 | navigationController?.pushViewController(passcodeView, animated: true) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /PasscodeKit/app/ViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## OVERVIEW 2 | 3 | PasscodeKit is a lightweight and easy-to-use, in-app Passcode implementation for iOS. 4 | 5 | 6 | 7 | ## INSTALLATION 8 | 9 | ### CocoaPods 10 | 11 | [CocoaPods](https://cocoapods.org) is a dependency manager for Swift and Objective-C Cocoa projects. 12 | 13 | To incorporate the **PasscodeKit** library into your Xcode project utilizing CocoaPods, please reference it within your `Podfile` as shown below: 14 | 15 | ```ruby 16 | pod 'PasscodeKit' 17 | ``` 18 | 19 | ### Swift Package Manager 20 | 21 | [Swift Package Manager](https://swift.org/package-manager) is a tool for managing the distribution of Swift code. 22 | 23 | To add **PasscodeKit** as a dependency to your project, follow these steps: 24 | 25 | 1. Open your Swift project in Xcode. 26 | 2. Navigate to `File` -> `Add Package Dependencies...`. 27 | 3. Paste `https://github.com/relatedcode/PasscodeKit.git` into the search bar. 28 | 4. Choose the version you want to use and click `Add Package`. 29 | 30 | ### Manually 31 | 32 | If you prefer not to use any of the dependency managers, you can integrate **PasscodeKit** into your project manually. Just copy all the `*.swift` files from the `PasscodeKit/Sources` folder into your Xcode project. 33 | 34 | ## REQUIREMENTS 35 | 36 | - iOS 12.0+ 37 | 38 | ## QUICKSTART 39 | 40 | To activate the PasscodeKit in your codebase, you need to start it right after the app is launched. The best practice to do it in the AppDelegate `didFinishLaunchingWithOptions` method. 41 | 42 | ```swift 43 | PasscodeKit.start() 44 | ``` 45 | 46 | The following `PasscodeKitDelegate` methods can be used to take actions related to the PasscodeKit user activity. 47 | 48 | ```swift 49 | func passcodeCheckedButDisabled() 50 | 51 | func passcodeEnteredSuccessfully() 52 | 53 | func passcodeMaximumFailedAttempts() 54 | ``` 55 | 56 | To enable, disable the passcode functionality, or to change the saved passcode you can use the following methods. 57 | 58 | ```swift 59 | PasscodeKit.createPasscode(self) 60 | 61 | PasscodeKit.changePasscode(self) 62 | 63 | PasscodeKit.removePasscode(self) 64 | ``` 65 | 66 | 67 | 68 | ## CUSTOMIZATION 69 | 70 | The following settings are available for customizing the passcode-related user experience. 71 | 72 | ```swift 73 | PasscodeKit.passcodeLength = 4 74 | 75 | PasscodeKit.allowedFailedAttempts = 3 76 | ``` 77 | 78 | ```swift 79 | PasscodeKit.textColor = .darkText 80 | PasscodeKit.backgroundColor = .lightGray 81 | 82 | PasscodeKit.failedTextColor = .white 83 | PasscodeKit.failedBackgroundColor = .systemRed 84 | ``` 85 | 86 | ```swift 87 | PasscodeKit.titleEnterPasscode = "Enter Passcode" 88 | PasscodeKit.titleCreatePasscode = "Create Passcode" 89 | PasscodeKit.titleChangePasscode = "Change Passcode" 90 | PasscodeKit.titleRemovePasscode = "Remove Passcode" 91 | 92 | PasscodeKit.textEnterPasscode = "Enter your passcode" 93 | PasscodeKit.textVerifyPasscode = "Verify your passcode" 94 | PasscodeKit.textEnterOldPasscode = "Enter your old passcode" 95 | PasscodeKit.textEnterNewPasscode = "Enter your new passcode" 96 | PasscodeKit.textVerifyNewPasscode = "Verify your new passcode" 97 | PasscodeKit.textFailedPasscode = "%d Failed Passcode Attempts" 98 | PasscodeKit.textPasscodeMismatch = "Passcodes did not match. Try again." 99 | PasscodeKit.textTouchIDAccessReason = "Please use Touch ID to unlock the app" 100 | ``` 101 | 102 | ## CONFIGURATION 103 | 104 | PasscodeKit supports both TouchID and FaceID. If you're using FaceID, be sure to add the `NSFaceIDUsageDescription` details into your Info.plist file. 105 | 106 | 107 | 108 | ## LICENSE 109 | 110 | MIT License 111 | 112 | Copyright (c) 2023 Related Code 113 | 114 | Permission is hereby granted, free of charge, to any person obtaining a copy 115 | of this software and associated documentation files (the "Software"), to deal 116 | in the Software without restriction, including without limitation the rights 117 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 118 | copies of the Software, and to permit persons to whom the Software is 119 | furnished to do so, subject to the following conditions: 120 | 121 | The above copyright notice and this permission notice shall be included in all 122 | copies or substantial portions of the Software. 123 | 124 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 125 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 126 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 127 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 128 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 129 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 130 | SOFTWARE. 131 | -------------------------------------------------------------------------------- /VERSION.txt: -------------------------------------------------------------------------------- 1 | 1.0.4 2 | --------------------------------------------------------------------------------