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
totp.verify("492039")
sleep 30
totp.verify("492039")
totp.provisioning_uri("alice@google.com")
Counter based OTP's
hotp = MultiFactorAuth::HOTP.new("base32secretkey3232")
hotp.at(0)
hotp.at(1)
hotp.at(1401)
hotp.verify("316439", 1401)
hotp.verify("316439", 1402)
Generating a Base32 Secret key
MultiFactorAuth::Base32.random_base32
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.