No commit activity in last 3 years
No release in over 3 years
A ruby library for generating one time passwords and QR Codes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 5.0
>= 0
~> 10.0

Runtime

~> 0.3.2
~> 3.1.0
~> 0.10.1
 Project Readme

MultiFactorAuth

A ruby library for generating one time passwords and QR Codes.

Installation

Add this line to your application's Gemfile:

gem 'multi_factor_auth'

And then execute:

$ bundle

Or install it yourself as:

$ gem install multi_factor_auth

Usage

Time based OTP's

totp = MultiFactorAuth::TOTP.new("base32secret3232", issuer: "My Service")
totp.now # => "492039"

# OTP verified for current time
totp.verify("492039") # => true
sleep 30
totp.verify("492039") # => false
totp.provisioning_uri("alice@google.com")

Counter based OTP's

hotp = MultiFactorAuth::HOTP.new("base32secretkey3232")
hotp.at(0) # => "260182"
hotp.at(1) # => "055283"
hotp.at(1401) # => "316439"

# OTP verified with a counter
hotp.verify("316439", 1401) # => true
hotp.verify("316439", 1402) # => false

Generating a Base32 Secret key

MultiFactorAuth::Base32.random_base32  # returns a 16 character base32 secret. Compatible with Google Authenticator

Generating a QR Code

totp = MultiFactorAuth::TOTP.new("base32secretkey3232")
qrcode = totp.qr_code("alice@google.com")
image = qrcode.as_png
svg = qrcode.as_svg
html = qrcode.as_html
string = qrcode.as_ansi
string = qrcode.to_s

Resources

Contributing

  • Fork the project
  • Send a pull request

License

Open source under the terms of the MIT License.