crotp

HOTP and TOTP implementation for two factor authentication totp otp 2fa two-factor-authentication hotp shard
0.1.1 released
philnash/crotp
62 10
Phil Nash

CrOTP

The Crystal One Time Password library.

Installation

Add this to your application's shard.yml:

dependencies:
  crotp:
    github: philnash/crotp

Usage

HOTP

require "crotp"

hotp = CrOTP::HOTP.new("secret")

# Generate a code
hotp.generate(counter)
# => "423748"

# Verify code
hotp.verify(token, counter)
# => true

TOTP

require "crotp"

totp = CrOTP::TOTP.new("secret")

# Generate a code
totp.generate
# => "423748"

# Generate a code at a specific time stamp
totp.generate(at: 3.minutes.ago)
# => "923832"

# Verify code (verifies against the current time)
totp.verify(token)
# => true

# Verify code at a specific time stamp
totp.verify(token, at: 3.minutes.ago)
# => true

Todo

  • [x] Basic HOTP and TOTP generation and verification
  • [x] Rewrite int_to_bytes and extract from CrOTP::OTP
  • [ ] Verifying a token over a window of counters/time
  • [ ] Google Authenticator otpauth URI generation
  • [ ] Ability to choose algorithm (currently only sha1)
  • [ ] Ability to choose size of period in TOTP

Contributing

  1. Fork it ( https://github.com/philnash/crotp/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • philnash Phil Nash - creator, maintainer
crotp:
  github: philnash/crotp
  version: ~> 0.1.1
License MIT
Crystal 0.20.1

Authors

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently