A modal passcode input and validation view controller for iOS

Overview

TOPasscodeViewController

A modal passcode input and validation view controller for iOS.

CI Version GitHub license Platform Beerpay PayPal Twitch

TOPasscodeViewController is an open-source UIViewController subclass that will overlay a full-screen passcode UI over an app's content. The user must enter the correct password into it in order to proceed, or hit 'Cancel' to exit the private part of the app.

This sort of UI is useful for certain apps that contain highly sensitive information (such as banking or health) where users may indeed want an extra level of security beyond the standard iOS passcode.

Features

  • Prompts users to enter a passcode in order to proceed.
  • May be presented as a translucent overlay, partially showing the normal app content behind it.
  • Supports 4 different passcode types, from 4-digit passcodes, up to full alphanumeric passcodes.
  • Supports 4 base themes, including translucent/opaque and light/dark.
  • Supports Touch ID validation.
  • Provides an additional settings view controller for letting users change their passcode.
  • Passcode validation is handled by the parent app through a variety of delegate callbacks.
  • A custom animation and layout when the device is rotated to landscape mode on iPhone.
  • Custom 'opening' and 'dismissal' animations.

System Requirements

iOS 8.3 or above

Installation

As a CocoaPods Dependency

Add the following to your Podfile:

pod 'TOPasscodeViewController'

As a Carthage Dependency

Coming soon. :)

Manual Installation

Download this project from GitHub, move the subfolder named 'TOPasscodeViewController' over to your project folder, and drag it into your Xcode project.

Examples

TOPasscodeViewController operates around a very strict modal implementation. It cannot be pushed to a UINavigationController stack, and must be presented as a full-screen dialog on an existing view controller.

Basic Implementation

- (void)showButtonTapped:(id)sender
{
    TOPasscodeViewController *passcodeViewController = [[TOPasscodeViewController alloc] initWithStyle:TOPasscodeViewStyleTranslucentDark passcodeType:TOPasscodeTypeFourDigits];
    passcodeViewController.delegate = self;
    [self presentViewController:passcodeViewController animated:YES completion:nil];
}

- (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code
{
    return [code isEqualToString:@"1234"];
}

Security

TOPasscodeViewController does not perform any password management on your behalf. Any passcodes the user enters are forwarded to your own code via its delegate, and it's up to you to perform the validation and return the result back to TOPasscodeViewController.

This was an intentional decision for security reasons. Instead of every app using TOPasscodeViewController implementing the exact same validation and storage code path, you're free to custom tailor the way passcodes are handled in your app as you see fit.

No matter which passcode type, all passcodes in TOPasscodeViewController are handled as strings. When storing them in your app, they should be given at least the same level of scrutiny as full passwords. As such, I would strongly recommend you generate a salted hash of any user-defined passcode, and store both the hash and the salt in a protected location, like the iOS secure keychain, or an encrypted Realm file.

Because passcodes are treated as generic strings, if the user has selected a different passcode type (like an arbitrary numerical or alphanumeric one), you should also store that setting alongside the hash as well.

How it works

There's nothing too crazy about how this view controller was created. All reusable components are broken out into separate UIView classes, and an all-encompassing TOPasscodeView class is used to pull as much view logic out of the view controller (one way of solving the Massive View Controller problem.)

Depending on the screen width of the device (or if an iPad is using split screen), a single class manages all of the values for laying out the content with the appropriate font sizes, margins and cIrcle sizes. This was done to ensure maximum granular control over the sizing of elements per device. When transitioning between two of these sizes, all image assets are regenerated to ensure proper pixel scaling.

The view controller heavily uses UIVisualEffectView to produce its translucent effect. When dealing with these, I discovered a few interesting tidbits:

  • For effect views that blur the content behind them, you can animate setting the effect property from nil to a UIBlurEffect object to produce a very nice gradually blurring transition effect.
  • Effect views with a UIVibrancyEffect CANNOT EVER have an alpha value less than 1.0. Trying to animate fading in one of these views will result in an effect that will be broken until the animation has completed. To fix this, I added a contentAlpha property to my subclasses that would manually target the alpha values of all subviews, but would leave the visual effect view itself at 1.0. This created the desired effect where the translucent content would fade in properly.

Is it App Store-safe?

UPDATE: No. In it's current form, it's getting rejected from the App Store. See issue #31.

This is a tricky question. App Review guideline 5.2.5 states that apps can't produce UIs that might be easily confused with system functionality, but this rule is incredibly subjective and will ultimately heavily depend on the app reviewer at the time.

Since the default style and text for this view controller make it very easily confused with the iOS lock screen, I would strongly recommend making these changes before shipping:

  • Set your app icon as the titleView property of TOPasscodeViewController to add more specialised branding to it.
  • Change the default tittle text to be more specific. Instead of 'Enter Passcode', put 'Enter MyApp Passcode to continue'.
  • Consider using the light style instead of the dark style.

All in all, this might still not be enough. If you do end up getting rejected by Apple for using this library, please file an issue here and we can look at what will need to be changed to let Apple approve it.

Credits

TOPasscodeViewController was originally created by Tim Oliver as a component for iComics, a comic reader app for iOS.

iOS Device mockups used in the screenshot created by Pixeden.

License

TOPasscodeViewController is licensed under the MIT License, please see the LICENSE file. analytics

Comments
  • iPhone X Support

    iPhone X Support

    • [x] I have read this issue template and provided all possible information.
    • [x] I'm using CocoaPods and have run pod update before filing this issue.

    Hardware / Software

    Which version of the library were you using? 0.0.1 Which version of iOS are you running? iOS 11 What model of iOS device were you testing on? iPhone X If using CocoaPods, which version of CocoaPods are you on? 1.3.1

    Goals

    What is the outcome result you want to achieve with this library?

    Provide the possibility to lock an app.

    Expected Results

    What did you expect to happen?

    A) Home indicator should respect safe area insets. B) Touch ID replacement for Face ID.

    Actual Results

    What happened instead? (Please attach a screenshot/screen recording if possible)

    simulator screen shot - iphone x - 2017-12-14 at 13 10 51 simulator screen shot - iphone x - 2017-12-14 at 13 11 09

    Steps to Reproduce

    What are the steps needed to reproduce this issue? If this bug was caused by a specific image, please post it here.

    A) Present a TOPasscodeSettingsViewController. B) Present a TOPasscodeViewController with allowBiometricValidation = YES;

    opened by lukeleleh 5
  • TOPasscodeKeypadView is inaccessible

    TOPasscodeKeypadView is inaccessible

    Hello.

    I have made TOPasscodeViewController.framework file from this project manually downloaded it. After I have Included this framework in Swift project. Made import TOPasscodeViewController. All was perfect, even can chow TOPasscodeViewController on screen. Seems all OK.

    BUT.

    When I started customization I found some limitations. TOPasscodeKeypadView under TOPasscodeView is inaccessible. Other simple props, like titleLabel is accecable. But keypadView and inputField is not.

    http://dl3.joxi.net/drive/2020/03/24/0014/1145/935033/33/2f38cbf5f1.jpg

    http://dl3.joxi.net/drive/2020/03/24/0014/1145/935033/33/0950b88d93.jpg

    Looks like not expected behavior, because it prevents from customization KeypadView. Now I am try to make it public and accessible. (move it from Private Headers to Headers)

    How I can access keypadView?

    Thanks.

    opened by ARGAMX 4
  • Allow custom keypad button border and lettering presence

    Allow custom keypad button border and lettering presence

    This PR adds two optional parameters to TOPasscodeViewController for controlling the presence of the border and the "ABC" lettering of the keypad circular buttons. I hope this can increase the UI design flexibility (and avoid being rejected by App Store).

    custom_border_letering

    The sample app has also been updated to demonstrate the new feature.

    opened by MacroYau 4
  • Cannot Enter Custom Numeric Pin

    Cannot Enter Custom Numeric Pin

    • [x] I have read this issue template and provided all possible information.
    • [x] I'm using CocoaPods and have run pod update before filing this issue.

    Hardware / Software

    Which version of the library were you using? pulled Nov 11, 2017 Which version of iOS are you running? iOS 11 What model of iOS device were you testing on? iPhone 7, iPhone 8 (simulator) If using CocoaPods, which version of CocoaPods are you on? 1.3.1

    Goals

    I'm testing the library and I find that when I setup a custom numeric pin, the TOPasscodeViewController does not allow me to enter the pin code I've set. The problem is there is no way to indicate the pin is complete.

    Expected Results

    I would expect to be able to enter the pin code.

    Actual Results

    TOPasscodeViewController keeps letting me enter digits and never ends. The only way out is to delete the digits entered and cancel the panel.

    Steps to Reproduce

    1. Run the TOPasscodeViewController example application.
    2. Summon the settings panel
    3. Set a new passcode by tapping on the Passcode row
    4. Enter the original passcode (1234)
    5. Tap the Passcode Options button
    6. Tap "Custom Numeric Code"
    7. Enter a code ("123")
    8. Tap Next
    9. Reenter the code ("123")
    10. Tap Done
    11. Tap Done again to exit the Settings panel
    12. Tap Enter Password
    13. Enter the code ("123")

    then what?

    bug 
    opened by alldritt 3
  • Add

    Add "allowCancel" to TOPasscodeViewController

    Adds a new "allowCancel" property on TOPasscodeViewController that turns off the default cancel button when set to NO, for use when the user can't proceed in the app at all without entering a passcode.

    opened by faec 2
  • iOS 11.2?

    iOS 11.2?

    • [ ] I have read this issue template and provided all possible information.
    • [x] I'm using CocoaPods and have run pod update before filing this issue.

    Please remove this section of the issue template before filing your issue.

    Thanks for considering filing an issue! Before proceeding, please consider the type of issue you're filing and make sure to supply the proper details needed for it! :)

    Please note that your issue may be closed without review if you do not supply the information that is requested here. Since this library is done as a side-project outside of work hours, please understand that a timely response cannot be guaranteed. ;)

    For CocoaPods Users

    Before filing a bug report, please make sure you are using the latest version of CocoaPods (gem install cocoapods), and the latest version of this library (pod repo update).

    Support for CocoaPods-related issues is not provided unless you confirm both of these points in your submission.

    Issue Types

    Questions: Please check the closed issues to see if it's already been asked before.

    Feature Request: Please fill in just the first two sections. Please be as thorough as possible and explain how you would expect this feature to work both visually, and from an API perspective.

    Bugs: Please be as thorough as possible when describe the bug you've discovered. If it's a visual bug, please add a screenshot. If it's an animation bug, please provide a recording of the bug in action.


    Hardware / Software

    Which version of the library were you using? Which version of iOS are you running? What model of iOS device were you testing on? If using CocoaPods, which version of CocoaPods are you on?

    Goals

    What is the outcome result you want to achieve with this library?

    Expected Results

    What did you expect to happen?

    Actual Results

    What happened instead? (Please attach a screenshot/screen recording if possible)

    Steps to Reproduce

    What are the steps needed to reproduce this issue? If this bug was caused by a specific image, please post it here.

    opened by yveszenne 2
  • Making library usable in extension targets

    Making library usable in extension targets

    Hi, this PR removes usage of UIApplication`s sharedApplication method to make library usable in extensions targets. (described in #5)

    I've run tests and did manual testing for all this cases so nothing should be broken:

    • [x] Presenting and dismissing the view controller in both portrait and landscape modes.
    • [x] Presenting the view controller, rotating the device and then dismissing from the new orientation.
    • [x] Presenting the view controller, then enabling split-screen on an iPad.
    • [x] Changing the split-screen window sizes on iPad.
    opened by Austinate 2
  • Cocoapods isn't available

    Cocoapods isn't available

    • [x] I have read this issue template and provided all possible information.
    • [x] I'm using CocoaPods and have run pod update before filing this issue.

    Please remove this section of the issue template before filing your issue.

    Thanks for considering filing an issue! Before proceeding, please consider the type of issue you're filing and make sure to supply the proper details needed for it! :)

    Please note that your issue may be closed without review if you do not supply the information that is requested here. Since this library is done as a side-project outside of work hours, please understand that a timely response cannot be guaranteed. ;)

    For CocoaPods Users

    Before filing a bug report, please make sure you are using the latest version of CocoaPods (gem install cocoapods), and the latest version of this library (pod repo update).

    Support for CocoaPods-related issues is not provided unless you confirm both of these points in your submission.

    Issue Types

    Questions: Please check the closed issues to see if it's already been asked before.

    Feature Request: Please fill in just the first two sections. Please be as thorough as possible and explain how you would expect this feature to work both visually, and from an API perspective.

    Bugs: Please be as thorough as possible when describe the bug you've discovered. If it's a visual bug, please add a screenshot. If it's an animation bug, please provide a recording of the bug in action.


    Hardware / Software

    Which version of the library were you using? Which version of iOS are you running? What model of iOS device were you testing on? If using CocoaPods, which version of CocoaPods are you on?

    Goals

    What is the outcome result you want to achieve with this library?

    Expected Results

    What did you expect to happen?

    Actual Results

    What happened instead? (Please attach a screenshot/screen recording if possible)

    Steps to Reproduce

    What are the steps needed to reproduce this issue? If this bug was caused by a specific image, please post it here.

    opened by dipeshparashar 2
  • Application rejected by Apple.

    Application rejected by Apple.

    Apple rejected application because of same Lock screen design that confuse user.

    So we are trying to apply titleView but its not working.

    self.pinAuthentication.passcodeView.titleView = {
                let i = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
                i.backgroundColor = .red
     //              //  let width = self.pinAuthentication.passcodeView.titleLabel.bounds.width
     //                let iview = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
    //                iview.image = UIImage(named:"AppIcon")
    //                iview.contentMode = .scaleAspectFit
                return i
                }()
    

    Can you please help us out to get out of this issue as we need to submit our App ASAP. We already use our custom title to create/enter/confirm PIN message

    bug 
    opened by tapannathvani 1
  • Added 'layoutIfNeeded' when changing the title of the cancel button.

    Added 'layoutIfNeeded' when changing the title of the cancel button.

    After allowCancel is set to false,

    When the cancel button is displayed after entering the passcode, the title of the cancel button is changed from 'cancel' to 'delete'.

    So I added a layoutIfNeeded function when the title of the cancel button changes.

    opened by jangsy7883 1
  • Add NSLocalizedString to

    Add NSLocalizedString to "Face ID" and "Touch ID" labels

    Apple Localized "Face ID" & "Touch ID" to "面容 ID" & "触控 ID" in iOS 11.2 Simplified Chinese Languages version, so this PR happens.

    opened by Jinya 1
  • Localize text with different languages

    Localize text with different languages

    Please make this lib is able to localize text with different languages. I did loop all subviews to change UILabels and UIButtons but some labels would not change text when running.

    Thanks team.

    enhancement 
    opened by luatvudinh 1
  • Update for iOS 13 and Dark Mode

    Update for iOS 13 and Dark Mode

    • [X] I have read this issue template and provided all possible information.
    • [ ] I'm using CocoaPods and have run pod update before filing this issue.


    Hardware / Software

    Which version of the library were you using? latest Which version of iOS are you running? iOS 13.4.1 What model of iOS device were you testing on? simulator If using CocoaPods, which version of CocoaPods are you on? n/a

    Goals

    A passcode protector that functions well and fits the latest iOS style

    Expected Results

    In iOS 13 Dark Mode, the Settings controller would be dark

    Actual Results

    In iOS 13 Dark Mode, the Settings controller is light

    Steps to Reproduce

    Run in Dark Mode in an iOS 13 app and access the Settings controller. Observe that it is light.

    enhancement 
    opened by inPhilly 1
  • Error on installation via Carthage

    Error on installation via Carthage

    Cartfile:

    github "TimOliver/TOPasscodeViewController"

    Terminal:

    iMac:App-iOS-Sources user$ carthage update --platform iOS --no-use-binaries *** Cloning TOPasscodeViewController *** Checking out TOPasscodeViewController at "0.0.2" *** xcodebuild output can be found in /var/folders/nb/9g4bcynn1bbbl93rrd7nns4h0000gn/T/carthage-xcodebuild.Hj36cs.log *** Skipped building TOPasscodeViewController due to the error: Dependency "TOPasscodeViewController" has no shared framework schemes for any of the platforms: iOS If you believe this to be an error, please file an issue with the maintainers at https://github.com/TimOliver/TOPasscodeViewController/issues/new

    How to fix this Error? I have 17 plugins from GitHub installed in the iOS project via Carthage. I want to install TOPasscodeViewController as a 18 plugin, but getting this Error. Thanks.

    Seems that fremework don't support Carthage yet. But seems adding Carthage support is quite easy task:

    https://amerhukic.com/how-to-add-carthage-support-in-existing-cocoapod-project

    https://webcache.googleusercontent.com/search?q=cache:gNv43se4RWIJ:https://amerhukic.com/how-to-add-carthage-support-in-existing-cocoapod-project

    https://github.com/Carthage/Carthage#share-your-xcode-schemes

    enhancement pr requested 
    opened by ARGAMX 2
  • Highlighting number issue

    Highlighting number issue

    Hi Team, I keep on entering the wrong password. At some point, a particular number gets highlighted (the entered digit) even I entered another number as well.

    Please refer the attached screenshot.

    Passcode

    opened by YuvaDev 0
  • Disable

    Disable "Passcode Options" button on TOPasscodeSettingsViewController

    • [X] I have read this issue template and provided all possible information.
    • [X] I'm using CocoaPods and have run pod update before filing this issue.

    It would be great if I could set a flag to remove/disable the "Passcode Options" button displayed when setting a passcode using TOPasscodeSettingsViewController. I only want to allow certain passcode types, and allowing a user to choose their own would violate that. I did not see any options or properties that would allow me to do so.

    opened by TheGeekPharaoh 0
Releases(0.0.1)
Owner
Tim Oliver
Gamer. Developer. Geek. iOS Software Engineer at @Instagram (prev. @Drivemode, @Realm). Lover of writing OSS code and singer of bad karaoke. 日本語もオッケ〜
Tim Oliver
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

Recruit Lifestyle Co. Ltd. 607 Sep 18, 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

null 17 Dec 6, 2022
An iOS passcode lock with TouchID authentication written in Swift.

PasscodeLock A Swift implementation of passcode lock for iOS with TouchID authentication. Installation PasscodeLock requires Swift 2.0 and Xcode 7 Car

Yanko Dimitrov 679 Nov 26, 2022
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

Roland Leth 627 Dec 2, 2022
An iOS passcode lock with TouchID authentication written in Swift.

PasscodeLock A Swift implementation of passcode lock for iOS with TouchID authentication. Originally created by @yankodimitrov, hope you're doing well

Serge Velikan 203 Dec 6, 2022
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

Charles Edge 2 Aug 29, 2022
FruitsDic-ios-practice - To Practice onboarding , List, detail and setting View

?? FruitsDic-ios-practice ?? 기능 상세 OnBoding Screen with Page Tab View Data model

Jacob Ko 0 Jan 12, 2022
Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.

Virgil Core SDK Objective-C/Swift Introduction | SDK Features | Installation | Configure SDK | Usage Examples | Docs | Support Introduction Virgil Sec

Virgil Security, Inc. 27 Jul 26, 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

Kitura 122 Dec 16, 2022
Safe and easy to use crypto for iOS and macOS

Swift-Sodium Swift-Sodium provides a safe and easy to use interface to perform common cryptographic operations on macOS, iOS, tvOS and watchOS. It lev

Frank Denis 483 Jan 5, 2023
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

Kitura 122 Dec 16, 2022
Native and encrypted password manager for iOS and macOS.

Open Sesame Native and encrypted password manager for iOS and macOS. What is it? OpenSesame is a free and powerful password manager that lets you mana

OpenSesame 432 Jan 7, 2023
A wrapper to make it really easy to deal with iOS, macOS, watchOS and Linux Keychain and store your user's credentials securely.

A wrapper (written only in Swift) to make it really easy to deal with iOS, macOS, watchOS and Linux Keychain and store your user's credentials securely.

Ezequiel Aceto 2 Mar 29, 2022
Oversecured Vulnerable iOS App is an iOS app that aggregates all the platform's known and popular security vulnerabilities.

Description Oversecured Vulnerable iOS App is an iOS app that aggregates all the platform's known and popular security vulnerabilities. List of vulner

Oversecured Inc 135 Dec 15, 2022
Simple, secure password and data management for individuals and teams

Padloc Simple, secure password and data management for individuals and teams (formerly known as Padlock). This repo is split into multiple packages: P

Padloc 2.1k Jan 8, 2023
PGPro can encrypt and decrypt messages as well as manage all your OpenPGP keys. It is free, simple and lightweight. Everything stays on your device. PGPro is made in Switzerland.

PGPro can encrypt and decrypt messages as well as manage all your OpenPGP keys. It is free, simple and lightweight. Everything stays on your device. P

Luca Näf 250 Jan 4, 2023
Cloak Swift - a tool and Tuist plugin to encrypt secrets and then pass them in an obfuscated form into applications

This is Cloak Swift - a tool and Tuist plugin to encrypt secrets and then pass them in an obfuscated form into applications.

Andrew Lord 3 Nov 9, 2022
CCCryptor (AES encryption) wrappers for iOS and Mac in Swift. -- For ObjC, see RNCryptor/RNCryptor-objc

RNCryptor Cross-language AES Encryptor/Decryptor data format. The primary targets are Swift and Objective-C, but implementations are available in C, C

null 3.3k Dec 30, 2022
Helper functions for saving text in Keychain securely for iOS, OS X, tvOS and watchOS.

Helper functions for storing text in Keychain for iOS, macOS, tvOS and WatchOS This is a collection of helper functions for saving text and data in th

Evgenii Neumerzhitckii 2.3k Dec 28, 2022