iOS 7 style Passcode Lock

Overview

LTHPasscodeViewController

Simple to use iOS 7 style Passcode - the one you get in Settings when changing your passcode.

How to use

Drag the contents of LTHPasscodeViewController to your project, or add pod 'LTHPasscodeViewController' to your Podfile (preffered).

If your app uses extensions, LTH_IS_APP_EXTENSION needs to be defined:

  • either in each target's Prefix.pch file, if there is one, via #define LTH_IS_APP_EXTENSION
  • or in each target's build settings, down to Preprocessor Macros, double click each of your schemes, click on the + on the popup that appears and add LTH_IS_APP_EXTENSION

Example, called in application:didFinishLaunchingWithOptions:

[LTHPasscodeViewController useKeychain:NO];
if ([LTHPasscodeViewController doesPasscodeExist]) {
	if ([LTHPasscodeViewController didPasscodeTimerEnd])
		[[LTHPasscodeViewController sharedUser] showLockScreenWithAnimation:YES
                                                                 withLogout:NO
                                                             andLogoutTitle:nil];
}
- (void)passcodeViewControllerWillClose;
- (void)maxNumberOfFailedAttemptsReached;
- (void)passcodeWasEnteredSuccessfully;
- (void)logoutButtonWasPressed;
- (NSTimeInterval)timerDuration;
- (void)saveTimerDuration:(NSTimeInterval)duration;
- (NSTimeInterval)timerStartTime;
- (void)saveTimerStartTime;
- (BOOL)didPasscodeTimerEnd;
- (void)deletePasscode;
- (void)savePasscode:(NSString *)passcode;
- (NSString *)passcode;
// All of them fall back on the Keychain if they are not implemented, even if [LTHPasscodeViewController useKeychain:NO] was called, for flexibility over what and where you save.
// Do you only want to save the passcode in a different location and leave everything else in the Keychain? Call [LTHPasscodeViewController useKeychain:NO], but only implement -savePasscode:
  • Open as a modal, or pushed for changing, enabling or disabling the passcode:
/**
 @param	viewController The view controller where the passcode view controller will be displayed.
 @param asModal        Set to YES to present as a modal, or to NO to push on the current nav stack.
 */
- (void)showForEnablingPasscodeInViewController:(UIViewController *)viewController asModal:(BOOL)isModal;
- (void)showForDisablingPasscodeInViewController:(UIViewController *)viewController asModal:(BOOL)isModal;
- (void)showForChangingPasscodeInViewController:(UIViewController *)viewController asModal:(BOOL)isModal;
  • Show the lock screen over the window:
- (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle;

// Example:
[[LTHPasscodeViewController sharedUser] showLockscreenWithAnimation:YES withLogout:NO andLogoutTitle:nil];
// Displayed with a slide up animation, which, combined with
// the keyboard sliding down animation, creates an "unlocking" impression.
  • Show the lock screen over a specific view. Works like the above method, but the size and center will be of the passed in view:
- (void)showLockScreenOver:(UIView *)superview withAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString *)logoutTitle;

// Example:
[[LTHPasscodeViewController sharedUser] showLockscreenOver:popover withAnimation:YES withLogout:NO andLogoutTitle:nil];
  • entering foreground and resigning is handled from within the class.

If you're using Storyboards and need to show the lockscreen right at launch, but it's acting weird, you could try and initialise your Storyboard by code, as suggested in this issue by Ben (thank you!).

Makes use of SFHFKeyChainUtils to save the passcode in the Keychain. I know he dropped support for it, but I updated it for ARC 2 years ago (with help) and I kept using it since. The 'new' version isn't updated to ARC anyway, so I saw no reason to switch to it, or to any other library.

Feel free to contact me, or open an issue if anything is unclear, bugged, or can be improved.

Screenshot Screenshot

Apps using this control

Expenses Planner, DigitalOcean Manager, LovelyHeroku, Flow Web Browser, Balance - Checkbook App, QIF Reader, Zee - Personal Finance, EZDiary, MEGA.

If you're using this control, I'd love hearing from you!

License

Licensed under MIT. If you'd like (or need) a license without attribution, don't hesitate to contact me.

Comments
  • application:didFinishLaunchingWithOptions: loop

    application:didFinishLaunchingWithOptions: loop

    Hi fellows!

    I'm using your excellent library in one of the apps i'm working on and i've come across a weird problem when using LTHPasscodeViewController to secure the access.

    I show the lock screen at application:didFinishLaunchingWithOptions: so the user encounters the lock screen on application launch. Subsequently i call the method to lock the screen in applicationWillEnterForeground for when the user puts the app in background, switches between app, etc...

    Everything works fine except for when i'm in the app, locked or not, then i double tap the home button to bring the app switcher and try to close the app. I slide the app up to terminate, the app terminates but immediately the prompt for the user's fingerprint appears again preventing the app from closing.

    I can close the app only by switching to another app then bring the app switcher and terminate the app.

    Any ideas?

    Thanks in advance.

    opened by zentraedi 11
  • After rotating to landscape and back to portrait location UI is broken

    After rotating to landscape and back to portrait location UI is broken

    Even if you rotate on previous page and then open passcode view in a portrait mode.

    Was able to reproduce on demo application by enabling landscape orientations in project, then launching the app, rotating it to landscape, rotating back to portrait and pressing button "enable" in the demo app.

    opened by alexsorokoletov 11
  • Showing Lock screen with a non-simple password

    Showing Lock screen with a non-simple password

    To show the full keyboard we call this:

    - (void)setIsSimple:(BOOL)isSimple inViewController:(UIViewController *)viewController asModal:(BOOL)isModal

    But it requires viewController to be non-nil. So how can I show it when app is coming from background, as I call

    - (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout andLogoutTitle:(NSString*)logoutTitle

    from the AppDelegate?

    opened by iltercengiz 11
  • Dismiss keyboard, no way to get it back

    Dismiss keyboard, no way to get it back

    On an iPad, if you tap on the close keyboard button at the bottom right.

    Even if you tap on the digits, there is no way for the keyboard to come back up

    opened by roarapps 10
  • I can't

    I can't "swipe the app out" when TouchID is enabled!

    I don't know what that screen in which you can swipe an app up to kill the process is called...

    So I double press Home button and this screen appears right?

    simulator screen shot jul 19 2016 4 23 51 pm

    Notice the app "EZDiary". That is the app using LTHPasscodeViewController. Now I swipe the app up to kill the process:

    simulator screen shot jul 19 2016 4 26 48 pm

    if the device doesn't have a TouchID, it kills the process just fine. However, if TouchID is enabled, just after I swiped the app up, the app opens again and ask me for the TouchID! Because of this, I can't kill the process! It's like an infinite loop!

    I basically put this code in viewDidLoad of the initial view controller:

        if LTHPasscodeViewController.doesPasscodeExist() {
            LTHPasscodeViewController.sharedUser().showLockScreenWithAnimation(true, withLogout: true, andLogoutTitle: nil)
        }
    

    Why did this happen? viewDidLoad certainly doesn't get called when I swipe the app up, right?

    Yeah I know I didn't put the code in the app delegate. But it doesn't seem to work if I put it there. The passcode view controller just doesn't show up. It only works if I put it in viewDidLoad.

    opened by Sweeper777 10
  • TouchID not showing on resuming app

    TouchID not showing on resuming app

    On devices, there's a number of times when I can pretty reliably end up with the Passcode prompt instead of TouchID.

    My setup:

    1. On applicationWillResignActive I call
    if self.passcodeEnteredRight {
         LTHPasscodeViewController.saveTimerDuration(60 * 5)
         LTHPasscodeViewController.saveTimerStartTime()
        }
    
    1. On applicationDidBecomeActive I call:
    if LTHPasscodeViewController.doesPasscodeExist() {
          if LTHPasscodeViewController.didPasscodeTimerEnd() {
            //immediately clear that it was previously entered correctly
            self.passcodeEnteredRight = false
            LTHPasscodeViewController.sharedUser().showLockScreenWithAnimation(true, withLogout: false, andLogoutTitle: "ResidentAdvantage")
          }
    

    (In didFinishLaunchingWithOptions I've tried adding LTHPasscodeViewController.sharedUser().disablePasscodeWhenApplicationEntersBackground(), which doesn't seem to change the outcome below)

    1. I run the app on my iPhone, validating with TouchID. Then if you directly lock the device, wait for the timer to end, and then unlock, I'm usually presented with the keypad to enter passcode. This also happens if you press the home button and then switch back to the app after the timer has expired.

    (This is in the setting of before the patch I sent the pull request in, combined in with the other pull request, where you would never be able to get to passcode before with TouchID. I haven't had a chance to figure out the lifecycle of this issue.)

    opened by sschale 10
  • When launching from background, LTHPVC doesn't work accurately.

    When launching from background, LTHPVC doesn't work accurately.

    If I launch the app from the background, LTHPVC does not properly register number input. We never actually ask LTHPVC to show the lock screen, it just shows up automatically. Which is great, but it doesn't actually work properly. ios simulator screen shot may 30 2014 3 11 54 pm

    ios simulator screen shot may 30 2014 3 12 09 pm

    opened by neerajbaid 9
  • Customizable localization tables & UI properties

    Customizable localization tables & UI properties

    Really cool stuff! Would love to put this into our app, but I have a few suggestions.

    It would be neat if some of the define macros could be turned into public properties to make it more customizable.

    My main issue is with the kLocalizationTableName. I'd love to be able to provide my own localization table. Our app is localized in german and we're using the informal way ("Du") of addressing to our users, whereas the pre-defined localization uses the formal "Sie". If the localization table name was an exposed property instead of a defined macro, it would be easy to address this issue.

    Further, making the UI more customizable to really integrate well with the look and feel of the apps that use this component (by turning constants like the label font/color definitions etc. into public properties) would be really awesome.

    Happy to create a PR if you're open to those suggestions!

    :sunflower:

    opened by julsh 9
  • Crashing when Device Orientation doesn´t contain Portrait and Upside Down

    Crashing when Device Orientation doesn´t contain Portrait and Upside Down

    If App starts directly in Landscape Mode, app crashes in Method "supportedInterfaceOrientations".

    - (NSUInteger)supportedInterfaceOrientations {
        if (_beingDisplayedAsLockscreen) return UIInterfaceOrientationMaskAll;
        // I'll be honest and mention I have no idea why this line of code below works.
        // Without it, if you present the passcode view as lockscreen (directly on the window)
        // and then inside of a modal, the orientation will be wrong.
        return UIInterfaceOrientationPortraitUpsideDown;
    }
    

    Possible Fix:

    return [super supportedInterfaceOrientations];
    

    But now: App starts without a crash in landscape mode, but orientation of the PasscodeView is wrong.

    Setup: LTHPasscodeViewController is used for an iPad Project with the following Device Orientations:

    bildschirmfoto 2013-10-05 um 23 48 19

    Any quick idea how to fix this?

    opened by jingx23 9
  • Crash on launching with Face ID support on iPhone X, iOS 11.4

    Crash on launching with Face ID support on iPhone X, iOS 11.4

    This isn't a bug in the library, but you are now required to add a NSFaceIDUsageDescription with some string value if you support Face ID for your passcode unlock. I'm not sure if there's a way to check the plist for this value at runtime and avoid initiating Face ID if it's missing, but the docs should probably be updated and I'm leaving this here for others to reference.

    To reproduce the issue:

    1. Launch an iPhone X or iPhone X simulator on iOS 11.4 with Face ID enabled and with faces enrolled
    2. Add a passcode to your app with biometric support enabled
    3. Re-launch the app to trigger the passcode lock
    4. You should get a crash at this point instead of a Face ID prompt.
    opened by mgod 8
  • Keyboard behind viewcontroller when launched app launched from local notification

    Keyboard behind viewcontroller when launched app launched from local notification

    When launching an app from a UILocationNotification the keyboard is missing or behind the controller..

    Can be reproduced by firign a local notification and launching the app via the notification.

    opened by cswelin 8
  • Adds Support for Swift Package Manager

    Adds Support for Swift Package Manager

    Adds support for SPM. See README.md for instructions on how to add it to your project.

    Finally got around to fixing this up again. Now that Apple supports Resources I was able to import the Localizations. I added to the LTHPasscodeViewControllerStrings method to search for the SPM bundle if it didn't find a localized string since Apple moves those localizations into its own bundle.

    opened by jaerod95 6
  • Add Korean language for

    Add Korean language for "Cannot reuse the same passcode"

    This key is absent in Korean strings. Would you add this key string? "Cannot reuse the same passcode" = "이전에 사용한 암호를 재사용할 수 없습니다.";

    opened by dobiho5 1
Owner
Roland Leth
Full-stack developer, specialized in iOS, focused on user experience.
Roland Leth
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
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
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

Tim Oliver 381 Dec 5, 2022
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

Tim Oliver 381 Dec 5, 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
Pass for iOS - an iOS client compatible with Pass command line application.

Pass is an iOS client compatible with ZX2C4's Pass command line application. It is a password manager using GPG for encryption and Git for version control.

Mingshen Sun 1.3k Dec 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
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
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
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
Simple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.

KeychainAccess KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs extremely easy and much mor

Kishikawa Katsumi 7.2k Dec 30, 2022
A simple Swift Keychain Wrapper for iOS, watchOS, and OS X.

Latch A simple Swift 2.0 Keychain Wrapper for iOS, watchOS 2, and OS X. Usage A proper example of how to use Latch can be seen in the tests. import La

Danielle 56 Oct 25, 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

Jason 1.5k Dec 30, 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
Valet lets you securely store data in the iOS, tvOS, or macOS Keychain without knowing a thing about how the Keychain works.

Valet Valet lets you securely store data in the iOS, tvOS, watchOS, or macOS Keychain without knowing a thing about how the Keychain works. It’s easy.

Square 3.8k Jan 4, 2023
🔒 Swift Obfuscator that protects iOS apps against reverse engineering attacks.

struct fjiovh4894bvic: XbuinvcxoDHFh3fjid { let VNfhnfn3219d: Vnahfi5n34djga func cxncjnx8fh83FDJSDd() -> Lghbna2gf0gmh3d { return vPAOSNdcbif

Bruno Rocha 2.1k Jan 9, 2023
Simple Objective-C wrapper for the keychain that works on Mac and iOS

SAMKeychain SAMKeychain is a simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system Keyc

Sam Soffes 5.4k Dec 29, 2022
🦋후릐의 iOS 이것저것 공부해보는 레포🦋

?? iOS Practice Repo ?? ?? 정신차려 후릐야.. "도약".. 해야지? ✨ ✨ ✨ iOS 개발을 공부한 걸 기록합니다. 날짜 공부한 내용 프로젝트 내용 정리 6월 16일 Expandable TableView ??‍?? ?? 6월 25일 FSCalend

Ruhee Kim 8 Aug 24, 2022