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.
Add the following line to your Podfile:
pod 'OneTimePassword', '~> 1.0'
Then run pod install
to install the latest version of the framework.
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
To generate the current password:
NSString *password = token.password;
OneTimePassword was created by Matt Rubin and is released under the MIT License.