Skip to content

Latest commit

 

History

History
55 lines (35 loc) · 2.36 KB

README.md

File metadata and controls

55 lines (35 loc) · 2.36 KB

OneTimePassword

TOTP and HOTP one-time passwords for iOS

Build Status CocoaPods MIT License Platform

This is an older version of the OneTimePassword library, which offers Objective-C compatibility. For a modern Swift API, check out the latest version.

The OneTimePassword library is the core of Authenticator. It can generate both time-based and counter-based one-time passwords as standardized in RFC 4226 and 6238. It can also read and generate the "otpauth://" URLs commonly used to set up OTP tokens, and can save and load tokens to and from the iOS secure keychain.

Installation

Add the following line to your Podfile:

pod 'OneTimePassword', '~> 1.0'

Then run pod install to install the latest version of the framework.

Usage

Create a Token

This example assumes the user provides the secret as a Base32-encoded string. To use the decoding function seen below, add #import <Base32/MF_Base32Additions.h> to the top of your Objective-C file.

NSString *name = @"...";
NSString *issuer = @"...";
NSString *secretString = @"...";

NSData *secretData = [NSData dataWithBase32String:secretString];

OTPToken *token = [OTPToken tokenWithType:OTPTokenTypeTimer secret:secretData name:name issuer:issuer ];

return token

Generate a One-Time Password

To generate the current password:

NSString *password = token.password;

License

OneTimePassword was created by Matt Rubin and is released under the MIT License.