A ready to use implementation of user authentication using either PIN or TouchID. Comes with Keychain wrapper to securely store PIN.
- iOS 8+
- Xcode 6.1+
The concept is to work in closures, so no context needs to be saved and jumped over - simply authenticate the user (or not) and proceed. If TouchID is present, it will always be superior to PIN authentication. If TouchID is not present, or fails to authenticate user, PIN dialog is shown. Number of attempts is set to 3.
All the strings used are wrapped with NSLocalizedString()
, so to localize to different languages, simply copy and paste all the used strings to your Strings.file in your project.
Authenticator.setUpPIN(self.navigationController!, completionClosure: { () -> Void in
// PIN has been set up
}, failureClosure: { (error) -> Void in
// An error has occurred
})
If authenticateUser
method is called without previously setting up PIN, setup dialog is shown instead. After PIN is set up, method behaves as though user has been authenticated.
Authenticator.authenticateUser(self.navigationController!, completionClosure: { () -> Void in
// The user has been authenticated
}, failureClosure: { (error) -> Void in
// Failed to authenticate the user
})
If resetPIN
method is called withou previously setting up PIN, setup dialog is shown instead.
Authenticator.resetPIN(self.navigationController!, completionClosure: { () -> Void in
// PIN has been successfully reset
}, failureClosure: { (error) -> Void in
// An error has occurred
})
Delete PIN is not protected because it is an atomic function serving only to delete the stored PIN in the keychain. To protect it, simply wrap authenticateUser
around it.
Authenticator.deletePIN({ () -> Void in
// PIN has been successfully deleted
}, failureClosure: { (error) -> Void in
// An error has occurred
})
- iOS 7 support (UIAlertController vs UIAlertDialog)
Authenticator is released under the MIT license. See LICENSE for details.