Yet Another OTP generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Otp.kt 355B

12345678
  1. package com.chameth.yaotp.algos
  2. import kotlin.math.max
  3. data class Otp(val otp: String, val expiresAt: Long?)
  4. internal fun newOtp(otp: Int, targetLength: Int, expiresAt: Long? = null) = Otp(pad(otp, targetLength), expiresAt)
  5. internal fun pad(otp: Int, targetLength: Int) = with(otp.toString()) { "0".repeat(max(0, targetLength - length)) + this }