0.0
No commit activity in last 3 years
No release in over 3 years
A TOTP generator, that includes validation, generation and send methods. See https://github.com/fboccacini/onetime-totp for reference and usage.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.3
 Project Readme

OneTime

Time-based One Time Password (TOTP) generator RubyGem

Installation

gem install onetime-totp

Usage

totp = OneTime.new('secret-token').generate

Constructor's options:

  • secret: user's secret token. Required
  • length: final password length (int). Default: 6
  • encryption: encryption algorithm, supports SSL supported algoritms (string). Default: 'SHA512'
  • step: time step for password generation, in seconds (int). Default: 30

Example: totp = OneTime.new('secret-token', length: 10, step: 10, encryption: 'SHA1')


Methods:

  • generate(time = Time.now, length: self.length, step: self.step, encryption: self.encryption, reset: false) Generates a password with the given options and stores it in self.password. If the reset flag is set, it resets the generation time also.

  • verify('password to verify', time: Time.now, length: self.length, step: self.step, encryption: self.encryption) Verifies a given password against a newly generated (with options)

  • call_service(url, user, payload, content_type: 'application/json', accept: '/') Sends a request to the specified url, user and payload. If a password wasn't generated previously, it generates one using current timestamp and combines it with the user ("user:password"), encodes the result in base64, and stores it in the Authentication field in the header.

Getters

  • password: returns generated password
  • secret: returns given secret
  • generation_time: returns generation timestamp
  • step: returns set step time
  • encryption: returns set encryption
  • length: returns set password length

Setters

  • step: sets step time
  • encryption: sets encryption type ('sha1',sha256','sha512')
  • length: sets password length