Swiftpack.co -  Package - belous/OTPKit
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A small library written in Swift for generation time-based one-time passwords
.package(url: "https://github.com/belous/OTPKit.git", from: "0.3.0")


A small library written in Swift which can generate time-based one-time passwords.

Swift codecov CodeFactor


  • In Package.swift add the following:
dependencies: [
    .package(url: "https://github.com/belous/OTPKit.git", from: "0.3.0"),
targets: [
        name: "MainApp",
        dependencies: ["OTPKit"]


Create a struct or class and confirm it to the OTPProvidable protocol:

public struct Secret: Codable, Equatable, Hashable {
    public let secret: String
    public let digits: Int
    public let movingFactor: MovingFactor
    public let hmacAlgorithm: HMACAlgorithm

    public init(secret: String,
                digits: Int = 6,
                movingFactor: MovingFactor = .timer(period: 30),
                hmacAlgorithm: HMACAlgorithm = .sha1) {
        self.secret = secret
        self.digits = digits
        self.movingFactor = movingFactor
        self.hmacAlgorithm = hmacAlgorithm

extension Secret: OTPProvidable {}

To generate the current password you can call func getOTP(for: date) on instance of your's OTPProvidable:

let secret = Secret(secret: "AABCDEFABCDEFABC")
let currentPassword = secret.getOTP(for: Date())


This project is made available under the terms of the MIT License.


Stars: 0
Last commit: 6 weeks ago

Release Notes

Docs, unit-tests and more
6 weeks ago
  • Added documentation generated by sourcedocs
  • Code converge by unit-tests is 98% now
  • Improved CI

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco