Swiftpack.co -  belous/OTPKit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
belous/OTPKit
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")

OTPKit

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

Swift codecov CodeFactor

Installation

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

Usage

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())

License

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

GitHub

link
Stars: 0
Last commit: 21 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Docs, unit-tests and more
22 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 | API