All Projects → mattrubin → Onetimepassword

mattrubin / Onetimepassword

Licence: mit
🔑 A small library for generating TOTP and HOTP one-time passwords on iOS.

Programming Languages

15916 projects

Projects that are alternatives of or similar to Onetimepassword

CrOTP - One Time Passwords for Crystal
Stars: ✭ 62 (-74.49%)
Mutual labels:  otp, totp, hotp, two-factor-authentication, 2fa
A small and easy-to-use one-time password generator library for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP).
Stars: ✭ 107 (-55.97%)
Mutual labels:  otp, totp, hotp, two-factor-authentication, 2fa
A Web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes
Stars: ✭ 664 (+173.25%)
Mutual labels:  otp, totp, hotp, two-factor-authentication, 2fa
🔑 One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator
Stars: ✭ 916 (+276.95%)
Mutual labels:  otp, 2fa, two-factor-authentication, hotp
One Time
One Time Password (TOTP and HOTP) library for Clojure. TOTP/HOTP is widely used for Two Factor / Multi Factor Authentication.
Stars: ✭ 129 (-46.91%)
Mutual labels:  2fa, totp, two-factor-authentication, hotp
A free, secure and open source app for Android to manage your 2-step verification tokens.
Stars: ✭ 2,692 (+1007.82%)
Mutual labels:  otp, 2fa, totp, hotp
Twofactor totp
🔑 Second factor TOTP (RFC 6238) provider for Nextcloud
Stars: ✭ 203 (-16.46%)
Mutual labels:  otp, 2fa, totp, two-factor-authentication
apache 2fa
Apache two-factor (2FA) authentication with Google Authenticator based on Time-based One-Time Password (TOTP) or HMAC-based one-time password (HOTP) Algorithms.
Stars: ✭ 63 (-74.07%)
Mutual labels:  totp, hotp, two-factor-authentication, 2fa
HMAC-based (HOTP) and Time-based (TOTP) One-Time Password manager. Works with Google Authenticator for Two-Factor Authentication.
Stars: ✭ 79 (-67.49%)
Mutual labels:  otp, totp, hotp, two-factor-authentication
Java Otp
A one-time password (HOTP/TOTP) library for Java
Stars: ✭ 265 (+9.05%)
Mutual labels:  2fa, totp, two-factor-authentication, hotp
Open source two-factor authentication for Android
Stars: ✭ 3,326 (+1268.72%)
Mutual labels:  otp, totp, two-factor-authentication, hotp
One Time Password (HOTP/TOTP) library for Node.js, Deno and browsers.
Stars: ✭ 135 (-44.44%)
Mutual labels:  otp, totp, two-factor-authentication, hotp
📱 Two-Factor Authentication (2FA) client for Android + Wear OS
Stars: ✭ 155 (-36.21%)
Mutual labels:  2fa, totp, two-factor-authentication, hotp
A .NET implementation of TOTP and HOTP for things like two-factor authentication codes.
Stars: ✭ 424 (+74.49%)
Mutual labels:  otp, 2fa, totp, two-factor-authentication
Enhanced fork of FreeOTP-Android providing a feature-rich 2FA authenticator
Stars: ✭ 223 (-8.23%)
Mutual labels:  otp, 2fa, totp, hotp
Go Guardian
Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to create powerful modern API and web authentication.
Stars: ✭ 204 (-16.05%)
Mutual labels:  2fa, totp, hotp
Yubikey Manager Qt
Cross-platform application for configuring any YubiKey over all USB interfaces.
Stars: ✭ 137 (-43.62%)
Mutual labels:  otp, 2fa, hotp
🔐 A PHP library for generating one time passwords according to RFC 4226 (HOTP) and the RFC 6238 (TOTP)
Stars: ✭ 857 (+252.67%)
Mutual labels:  otp, totp, hotp
Highly secure and easy to use OTP client written in C/GTK that supports both TOTP and HOTP
Stars: ✭ 206 (-15.23%)
Mutual labels:  otp, totp, hotp
Minimal TOTP generator in 20 lines of Python
Stars: ✭ 678 (+179.01%)
Mutual labels:  2fa, totp, hotp


TOTP and HOTP one-time passwords for iOS

Build Status Code Coverage Swift 4.2 or 5.0 Available via Carthage and CocoaPods Platforms: iOS, watchOS MIT License

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 RFC 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 Cartfile:

github "mattrubin/OneTimePassword" ~> 3.2

Then run carthage update OneTimePassword to install the latest version of the framework.

Be sure to check the Carthage README file for the latest instructions on adding frameworks to an application.


Add the following line to your Podfile:

pod 'OneTimePassword', '~> 3.2'

OneTimePassword, like all pods written in Swift, can only be integrated as a framework. Make sure to add the line use_frameworks! to your Podfile or target to opt into frameworks instead of static libraries.

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


The latest version of OneTimePassword can be compiled with either Swift 4.2 or Swift 5, and can be linked with Swift 4 or Swift 5 projects using the Swift compiler's compatibility mode. To use OneTimePassword with earlier versions of Swift, check out the swift-4, swift-3, and swift-2.3 branches. To use OneTimePassword in an Objective-C based project, check out the objc branch and the 1.x releases.

Create a Token

The Generator struct contains the parameters necessary to generate a one-time password. The Token struct associates a generator with a name and an issuer string.

To initialize a token with an otpauth:// url:

if let token = Token(url: url) {
    print("Password: \(token.currentPassword)")
} else {
    print("Invalid token URL")

To create a generator and a token from user input:

This example assumes the user provides the secret as a Base32-encoded string. To use the decoding function seen below, add import Base32 to the top of your Swift file.

let name = "..."
let issuer = "..."
let secretString = "..."

guard let secretData = secretString),
    !secretData.isEmpty else {
        print("Invalid secret")
        return nil

guard let generator = Generator(
    factor: .timer(period: 30),
    secret: secretData,
    algorithm: .sha1,
    digits: 6) else {
        print("Invalid generator parameters")
        return nil

let token = Token(name: name, issuer: issuer, generator: generator)
return token

Generate a One-Time Password

To generate the current password:

let password = token.currentPassword

To generate the password at a specific point in time:

let time = Date(timeIntervalSince1970: ...)
do {
    let passwordAtTime = try token.generator.password(at: time)
    print("Password at time: \(passwordAtTime)")
} catch {
    print("Cannot generate password for invalid time \(time)")


Token persistence is managed by the Keychain class, which represents the iOS system keychain.

let keychain = Keychain.sharedInstance

The PersistentToken struct represents a Token that has been saved to the keychain, and associates a token with a keychain-provided data identifier.

To save a token to the keychain:

do {
    let persistentToken = try keychain.add(token)
    print("Saved to keychain with identifier: \(persistentToken.identifier)")
} catch {
    print("Keychain error: \(error)")

To retrieve a token from the keychain:

do {
    if let persistentToken = try keychain.persistentToken(withIdentifier: identifier) {
        print("Retrieved token: \(persistentToken.token)")
    // Or...
    let persistentTokens = try keychain.allPersistentTokens()
    print("All tokens: \({ $0.token }))")
} catch {
    print("Keychain error: \(error)")

To update a saved token in the keychain:

do {
    let updatedPersistentToken = try keychain.update(persistentToken, with: token)
    print("Updated token: \(updatedPersistentToken)")
} catch {
    print("Keychain error: \(error)")

To delete a token from the keychain:

do {
    try keychain.delete(persistentToken)
    print("Deleted token.")
} catch {
    print("Keychain error: \(error)")


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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].