An iOS passcode lock with TouchID authentication written in Swift.

Last update: May 4, 2022

PasscodeLock

A Swift implementation of passcode lock for iOS with TouchID authentication.

Installation

PasscodeLock requires Swift 2.0 and Xcode 7

Carthage

Add the following line to your Cartfile

github "yankodimitrov/SwiftPasscodeLock"

Usage

  1. Create an implementation of the PasscodeRepositoryType protocol.

  2. Create an implementation of the PasscodeLockConfigurationType protocol and set your preferred passcode lock configuration options. If you set the maximumInccorectPasscodeAttempts to a number greather than zero when the user reaches that number of incorrect passcode attempts a notification with name PasscodeLockIncorrectPasscodeNotification will be posted on the default NSNotificationCenter.

  3. Create an instance of the PasscodeLockPresenter class. Next inside your UIApplicationDelegate implementation call it to present the passcode in didFinishLaunchingWithOptions and applicationDidEnterBackground methods. The passcode lock will be presented only if your user has set a passcode.

  4. Allow your users to set a passcode by presenting the PasscodeLockViewController in .SetPasscode state:

let configuration = ... // your implementation of the PasscodeLockConfigurationType protocol

let passcodeVC = PasscodeLockViewController(state: .SetPasscode, configuration: configuration)

presentViewController(passcodeVC, animated: true, completion: nil)

You can present the PasscodeLockViewController in one of the four initial states using the LockState enumeration options: .EnterPasscode, .SetPasscode, .ChangePasscode, .RemovePasscode.

Also you can set the initial passcode lock state to your own implementation of the PasscodeLockStateType protocol.

Customization

Custom Design

The PasscodeLock will look for PasscodeLockView.xib inside your app bundle and if it can't find it will load its default one, so if you want to have a custom design create a new xib with the name PasscodeLockView and set its owner to an instance of PasscodeLockViewController class and module to PasscodeLock.

Then connect the view outlet to the view of your xib file and make sure to connect the remaining IBOutlets and IBActions. Also make sure to set module to PasscodeLock on all PasscodeSignPlaceholderView and PasscodeSignButton in the nib.

PasscodeLock comes with two view components: PasscodeSignPlaceholderView and PasscodeSignButton that you can use to create your own custom designs. Both classes are @IBDesignable and @IBInspectable, so you can see their appearance and change their properties right inside the interface builder:

Localization

Take a look at PasscodeLock/en.lproj/PasscodeLock.strings for the localization keys. Here again the PasscodeLock will look for the PasscodeLock.strings file inside your app bundle and if it can't find it will use the default localization file.

Demo App

The demo app comes with a simple implementation of the PasscodeRepositoryType protocol that is using the NSUserDefaults to store an retrieve the passcode. In your real applications you will probably want to use the Keychain API. Keep in mind that the Keychain records will not be removed when your user deletes your app.

GitHub

https://github.com/yankodimitrov/SwiftPasscodeLock
Comments
  • 1. Custom Design

    Hi! I compile framework with Carthage, and add PasscodeLockView.xib, PasscodeSignButton.swift, PasscodeSignPlaceholderView.swift to project. For PasscodeLockView.xib set owner PasscodeLockViewController class. After compile passcode show normal, but after tap on number pad got error "PasscodeLock was compiled with optimization - stepping may behave oddly; variables may not be available." What am i doing wrong ?

    Reviewed by kiokumicu at 2015-10-19 19:44
  • 2. Bug: TouchID not showing when Passcode enabled

    If I toggle the passcode switch to 'on', set a passcode, and then leave the app. Upon returning, I'm greeted with the new passcode, but no touchID authentication modal. I have to kill the app, and then enter it to get the touchID authentication modal to present.

    Reviewed by gblotter at 2015-08-26 22:14
  • 3. Simultaneous accesses to *, but modification requires exclusive access

    I've an app written in Swift 4, but it crashes at the end of Passcode set. Here the lines of code I used to open Passcode set interface:

    let passcodeVC = PasscodeLockViewController(state: .setPasscode, configuration: configuration)
    present(passcodeVC, animated: true, completion: nil)
    passcodeVC.successCallback = { lock in
        passcodeVC.dismiss(animated: true, completion: nil)
    }
    

    Here what the console has printed:

    Simultaneous accesses to 0x1c40ed9c8, but modification requires exclusive access.
    Previous access (a modification) started at Smartface`PasscodeLock.addSign(_:) + 912 (0x104a269bc).
    

    That is the highlighted function when the app crashes (it's in PasscodeLock.swift):

    open func changeStateTo(_ state: PasscodeLockStateType) {
        self.lockState = state // this assignment is highlighted when the app crashes
        delegate?.passcodeLockDidChangeState(self)
    }
    
    Reviewed by riccardoch at 2017-10-03 10:32
  • 4. Support of passcodes longer than 4 digits

    Great repository, thanks for sharing! :clap:

    Do you have any plans for supporting passcodes longer than 4 digits? i.e. would be great.

    If not, do you want to give me some pointers on how to do it?

    Thanks! :panos

    Reviewed by le4ker at 2016-06-06 10:30
  • 5. Cancel in all passcode states.

    By default .SetPasscode state has the cancel button. But in .EnterPasscode state cancel button is missing. Is there a simple way to enable cancel button in .EnterPasscode state?

    Awesome lib! Thanks! @ziogaschr , @szappanyos , @yankodimitrov , @maximbilan , @gblotter

    Reviewed by raugustinas at 2016-06-03 07:18
  • 6. Add Cocoapods support

    Hello @yankodimitrov. Thanks for the great work you've done so far in this lib.

    I have added cocoapods support. I left your PasscodeKeychainRepository and PasscodeNSUserDefaultsRepository out, as I think that there is no need for someone to load them both in his code and this will be different for each app.

    I was thinking that you might want to create a second pod, like SwiftPasscodeLockFull, that will include them. Which I don't really like as an idea.

    Also I have added support for overwriting PasscodeLock.strings and/or PasscodeView.xib in your app. So as dev can easily change things without worrying about broken library updates using cocoapods.

    Please check everything in .podspec, like version and license.

    Reviewed by ziogaschr at 2015-08-21 13:04
  • 7. Can I pass segue from passcode viewController?

    Can I pass segue from passcode ViewController to another ViewController wherein I allow to select folders where user want to enable password and dissmis that ViewController on Save?

    Reviewed by chirayu25 at 2017-07-06 18:41
  • 8. Interface Builder couldn't/wouldn't recognize the PasscodeSignPlaceholderView or PasscodeSignButton classes

    I don't now if this is an Xcode 7 beta issue, or if I'm the only one... But when I tried implementing a custom xib file, as described here:

    "PasscodeLock comes with two view components: PasscodeSignPlaceholderView and PasscodeSignButton that you can use to create your own custom designs. Both classes are @IBDesignable and @IBInspectable, so you can see their appearance and change their properties right inside the interface builder"

    Interface Builder couldn't/wouldn't recognize the PasscodeSignPlaceholderView or PasscodeSignButton classes when I tried associating them with UIButtons, UIViews, etc.

    Reviewed by gblotter at 2015-09-03 17:12
  • 9. [Question] How to "kill" the PasscodeViewController

    First of all, great stuff!

    Second, I have the scenario where a user reaches the max number of passcode attempts. When this happens, I want to delete all the sensitive information of the app and destroy the PasscodeViewController.

    How can I do the latter?

    Thanks! :panos

    Reviewed by le4ker at 2016-05-21 00:42
  • 10. Minor improvements

    Hello @yankodimitrov. Here are all the changes I had todo so as this excellent lib works with an app we have released at Apple Store. I think all the below changes will/can help other developers integrate your lib based on their needs.

    Please take a look, and let me know if you want me to change something or you need me to explain anything.

    p.s: Sorry for having merged the #8 in this branch, but it helped me using it in our project. I can remove this commit from the branch if you think so.

    Cheers, Chris

    Reviewed by ziogaschr at 2015-10-27 00:19
  • 11. PasscodeLockViewController must have a successCallback

    I have the need to set a successCallback to PasscodeLockViewController. I see that there are two options:

    1. add a public var successCallback: ((lock: PasscodeLockType) -> Void)? which is then set as passcodeLockVC.successCallback
    2. make the passcodeLockVC a public var.

    p.s.: Why the successCallback passes the lock: PasscodeLockType. Can you give me a good example? I might benefit from that.

    Reviewed by ziogaschr at 2015-09-19 16:43
  • 12. Perforce branch might be sync'ed multiple times with different

    Perforce branch might be sync'ed multiple times with different revision numbers (by the command "git p4 sync --branch=NAME //perforce/path...")

    In such situation, git p4 will see multiple perforce branches with same name and different revision numbers. The problem is that to make a shelve, git-p4 script will try to find "origin" branch, if not specified in command line explicitly. And previously script selected any branch with same name and don't mention particular revision number. Later this may cause failure of the command "git diff-tree -r $rev^ $rev", so shelve can't be created (due to wrong origin branch/commit).

    This commit fixes the heuristic by which git p4 selects origin branch: first it tries to select branch with same perforce path and perforce revision, and if it fails, then selects branch with only same perforce path (ignoring perforce revision number).

    Thanks for taking the time to contribute to Git! Please be advised that the Git community does not use github.com for their contributions. Instead, we use a mailing list ([email protected]) for code submissions, code reviews, and bug reports. Nevertheless, you can use GitGitGadget (https://gitgitgadget.github.io/) to conveniently send your Pull Requests commits to our mailing list.

    Please read the "guidelines for contributing" linked above!

    Originally posted by @kfrolov in https://github.com/git/git/pull/1229

    Reviewed by trojanwarhorse1 at 2022-03-20 00:19
  • 13. crash when set password

    Simultaneous accesses to 0x1c02f2248, but modification requires exclusive access. Previous access (a modification) started at PasscodeLock`PasscodeLock.addSign(:) + 912 (0x1059637bc). Current access (a modification) started at: 0 libswiftCore.dylib 0x0000000105cf1358 swift_beginAccess + 468 1 PasscodeLock 0x0000000105963b7c PasscodeLock.changeStateTo(:) + 168 2 PasscodeLock 0x00000001059649d8 protocol witness for PasscodeLockType.changeStateTo(:) in conformance PasscodeLock + 64 3 PasscodeLock 0x000000010594bc20 SetPasscodeState.acceptPasscode(:fromLock:) + 516 4 PasscodeLock 0x000000010594c304 protocol witness for PasscodeLockStateType.acceptPasscode(:fromLock:) in conformance SetPasscodeState + 196 5 PasscodeLock 0x000000010596342c PasscodeLock.addSign(:) + 1060 6 PasscodeLock 0x0000000105964910 protocol witness for PasscodeLockType.addSign(:) in conformance PasscodeLock + 92 7 PasscodeLock 0x000000010595de54 PasscodeLockViewController.passcodeSignButtonTap(:) + 216 8 PasscodeLock 0x000000010595df54 @objc PasscodeLockViewController.passcodeSignButtonTap(_:) + 72

    Reviewed by foolbear at 2017-11-14 04:23
iOS 7 style Passcode Lock
iOS 7 style Passcode Lock

LTHPasscodeViewController Simple to use iOS 7 style Passcode - the one you get in Settings when changing your passcode. How to use Drag the contents o

May 28, 2022
A library for make a beautiful Passcode Lock View
A library for make a beautiful Passcode Lock View

SmileLock A library for make a beautiful Passcode Lock View, also support Touch ID. Requirements iOS 9.0+ Swift 4 (pod version 3.x), Swift 3 (pod vers

Jun 15, 2022
The TouchID authentication mechanism implemented in Swift.

iOS-TouchID-Swift The TouchID authentication mechanism implemented in Swift About In iOS 8, Apple provides a new framework named LocalAuthentication w

May 20, 2018
Framework for biometric authentication (via TouchID) in your application
Framework for biometric authentication (via TouchID) in your application

Features Requirements Communication Installation Usage Intro Biometric authentication availability Feature enabled/disabled for biometric authenticati

Apr 24, 2022
Use Apple FaceID or TouchID authentication in your app using BiometricAuthentication.
Use Apple FaceID or TouchID authentication in your app using BiometricAuthentication.

BiometricAuthentication Use Apple FaceID or TouchID authentication in your app using BiometricAuthentication. It's very simple and easy to use that ha

Jun 15, 2022
TouchID used easy on one line in your ViewController.

TouchIDExtension TouchID used easy on one line in your ViewController. ##Installation At this moment, You can install only a way, manually. For instal

Feb 26, 2020
TouchEncryptedJson - Simple project that accepts an input and encrypts it with the TouchID on a Mac

TouchEncryptedJson Simple project that accepts an input and encrypts it with the

Feb 11, 2022
iOS 14 checkra1n-jailbreak-targeted passcode interposition

lockdown I can't remember if this version (involving ksecured) is actually functioning, Started working on this right before I moved, haven't really w

Jun 15, 2022
A modal passcode input and validation view controller for iOS
A modal passcode input and validation view controller for iOS

TOPasscodeViewController A modal passcode input and validation view controller for iOS. TOPasscodeViewController is an open-source UIViewController su

Jun 12, 2022
Very simple swift wrapper for Biometric Authentication Services (Touch ID) on iOS.

SimpleTouch Very simple swift wrapper for Biometric Authentication Services (Touch ID) on iOS. Sample Project There is a SimpleTouchDemo target define

Mar 18, 2022
Two-Factor Authentication Client for iOS

Authenticator Two-Factor Authentication Client for iOS. Authenticator is a simple, free, and open source two-factor authentication app. It helps keep

Jun 24, 2022
An easy-to-use, open-source two-factor authentication app designed specifically for iOS.
An easy-to-use, open-source two-factor authentication app designed specifically for iOS.

Tofu An easy-to-use, open-source two-factor authentication app designed specifically for iOS. Tofu generates one-time passwords to help you protect yo

Jun 18, 2022
LocalAuth - Another Fusion library to implement the local authentication using Biometry

FusionLocalAuth Another Fusion library to implement the local authentication usi

Jan 13, 2022
The minimalistic, secure and open-source two-factor authentication app.
The minimalistic, secure and open-source two-factor authentication app.

Einmal /ˈainmaːl/ German: once The minimalistic, secure and open-source two-factor authentication app. Features ♻️ Cross-platform — available on Andro

Jun 7, 2022
A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.

SwiftKeychainWrapper A simple wrapper for the iOS / tvOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift. Prov

Jun 25, 2022
A wrapper for Apple's Common Crypto library written in Swift.

IDZSwiftCommonCrypto A Swift wrapper for Apple's CommonCrypto library. IDZSwiftCommonCrypto works with both CocoaPods and Cathage. For more details on

Apr 8, 2022
A framework for the JOSE standards JWS, JWE, and JWK written in Swift.

JOSESwift is a modular and extensible framework for the JOSE standards JWS, JWE, and JWK written in Swift. ?? Please note that this implementation of

May 12, 2022
KeyClip is yet another Keychain library written in Swift.

KeyClip KeyClip is yet another Keychain library written in Swift. Features Multi Types ( String / NSDictionary / NSData ) Error Handling Settings ( kS

Feb 2, 2022
RSA public/private key encryption, private key signing and public key verification in Swift using the Swift Package Manager. Works on iOS, macOS, and Linux (work in progress).

BlueRSA Swift cross-platform RSA wrapper library for RSA encryption and signing. Works on supported Apple platforms (using Security framework). Linux

May 31, 2022