No description
Find a file
Huy Doan 8dc44b06f8
Merge pull request #9 from termermc/master
Fixed wrong default secret size in README
2023-10-07 09:44:10 +07:00
.github add github actions 2023-09-27 07:48:17 +07:00
tests add github actions 2023-09-27 07:48:17 +07:00
.gitignore Initial commit 2015-05-27 03:27:31 +07:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2023-09-26 20:35:58 +07:00
LICENSE Initial commit 2015-05-27 03:27:31 +07:00
otp.nim raise default secret size to 128 2023-09-29 05:09:08 +00:00
otp.nimble Update otp.nimble 2023-10-02 12:57:02 +07:00
README.md Fixed wrong default secret size in README 2023-10-07 01:34:00 +00:00

otp.nim build

This module implements One Time Password library for Nim.

Installation

$ nimble install otp

Changes

0.1.1 - initial release

Usage

import otp

let htop = Hotp.init("S3cret")
assert hotp.at(0) == 755224
assert hotp.at(1) == 287082

assert htop.verify(755224, 0) == true

echo hotp.provisioning_uri("mark@percival")

var totp = Totp.init("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ")
assert totp.at(1111111111) == 50471
assert totp.at(1234567890) == 5924
assert totp.at(2000000000) == 279037

totp = Totp.init("blahblah")
echo totp.now()

This library uses the wonderful stack_strings library for secrets. Meaning secrets are fixed length one can use --otp.secretSize:50 to override the size. By default the secret length is 128 bytes. Due to this the best way to handle secrets is as follows:

let mySecret = "S3cret"
if mySecret.len < secretSize:
  let hotp = Hotp.init(mySecret)
  assert hotp.at(0) == 755224
else:
  # Do something errory here
  raise (ref ValueError)(msg: "Secret size too large")