Code Monkey home page Code Monkey logo

smiletouchid's Introduction

SmileTouchID

A library for integrate Touch ID & Passcode to iOS App conveniently.

#What can it do for you?

1. Handle all complicated things about Touch ID & Passcode. You just need to write a few simple code to integrate Touch ID & Passcode to your app.

For example, handle the device that not support Touch ID, instead of Touch ID, use Passcode for authentication.

handle the whole process about securing the app (the user change passcode or turn passcode off),

if ([SmileAuthenticator hasPassword]) {
        [SmileAuthenticator sharedInstance].securityType = INPUT_TOUCHID;
        [[SmileAuthenticator sharedInstance] presentAuthViewController];
    }
2. Get elegant animation automatically and adaptive UI.

3. Can use storyboard customize the color to fit your app.

4. Can customize passcode digit to 4 digit, 7 digit passcode or any digit, and automatically configure for you.

#Theoretical Introduction

The main class is the SmileAuthenticator. It has a property SecurityType that has four types: INPUT_ONCE, INPUT_TWICE, INPUT_THREE, INPUT_TOUCHID. The reason for this name is that show the user input times.

INPUT_ONCE: For the user turn the passcode switch off, user need input their passcode only one time for turn the password off.

INPUT_TWICE: For the user turn the password switch on, user need input their password once and re-enter their password one more time for confirm it to match each other.

INPUT_THREE: For the user change the password, user need input their old passcode one time, then input their new passcode one time and re-enter one time for confirm, a total of three times.

INPUT_TOUCHID: For the user open the app, user can use touch ID or input passcode to unlock.

Use [[SmileAuthenticator sharedInstance] presentAuthViewController] to present view for authentication.

#How to use it for your project?

Step 1. Drop the fold SmileAuth to your project.

Step 2. Import SmileAuthenticator.h to your AppDelegate.m, and add below line to didFinishLaunchingWithOptions.

[SmileAuthenticator sharedInstance].rootVC = self.window.rootViewController;

Step 3. In your project root view controller, add below line to viewDidAppear:.

if ([SmileAuthenticator hasPassword]) {
        [SmileAuthenticator sharedInstance].securityType = INPUT_TOUCHID;
        [[SmileAuthenticator sharedInstance] presentAuthViewController];
    }

Step 4. Configure with your interactive UI parts, set appropriate securityType, then call presentAuthViewController.

For example below image show a switch to turn the passcode on/off, when the switch turn on, the securityType is INPUT_TWICE, when turn off, the securityType is INPUT_ONCE. A button for change passcode, the securityType is INPUT_THREE.

- (IBAction)changePassword:(id)sender {
    [SmileAuthenticator sharedInstance].securityType = INPUT_THREE;
    [[SmileAuthenticator sharedInstance] presentAuthViewController];
}

- (IBAction)passwordSwitch:(UISwitch*)passwordSwitch {
    if (passwordSwitch.on) {
        [SmileAuthenticator sharedInstance].securityType = INPUT_TWICE;
    } else {
        [SmileAuthenticator sharedInstance].securityType = INPUT_ONCE;
    }
    
    [[SmileAuthenticator sharedInstance] presentAuthViewController];
}

Update your interactive UI parts in viewWillAppear.

For example, below code show update the switch and button based on [SmileAuthenticator hasPassword].

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if ([SmileAuthenticator hasPassword]) {
        self.mySwitch.on = YES;
        self.changePasswordButton.hidden = NO;
    } else {
        self.mySwitch.on = NO;
        self.changePasswordButton.hidden = YES;
    }
}

Step 5. Build your project, very simple :)

#About Customization & Delegate callback

Open SmileSettingVC.storyboard customize the color.

Open SmileAuthenticator.h , change kPasswordLength to customize passcode digit.

SmileAuthenticator has a delegate that can get more information about the process of authentication.

The delegate name is AuthenticatorDelegate. It has four optional method.

@protocol AuthenticatorDelegate <NSObject>
@optional
/*!The method is called when AuthViewController be presented*/
-(void)AuthViewControllerPresented;
@optional
/*!The method is called when AuthViewController be dismissed*/
-(void)AuthViewControllerDismssed;
@optional
/*!The method is called when user success authentication by using Touch ID & Passcode*/
-(void)userSuccessAuthentication;
@optional
/*!The method is called when authentication failed*/
-(void)userFailAuthenticationWithCount:(NSInteger)failCount;
@end

Contact

  • If you have some advice or find some issue, please contact me.
  • Email me

Thanks

Thanks for raywenderlich's tutorial about securing iOS User Data, I am inspired by this tutorial.

License

SmileTouchID is available under the MIT license. See the LICENSE file for more info.

smiletouchid's People

Contributors

liu044100 avatar

Watchers

Alvin Cris Uy avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.