A ruby library for generating one time passwords (HOTP & TOTP) according to RFC 4226 and RFC 6238.
ROTP is compatible with the Google Authenticator available for Android and iPhone.
Many websites use this for multi-factor authentication, such as GMail, Facebook, Amazon EC2, WordPress, and Salesforce. You can find the whole list here.
- OpenSSL
- Ruby 1.9.3 or higher
gem install rotptotp = ROTP::TOTP.new("base32secret3232")
totp.now # => "492039"
# OTP verified for current time
totp.verify("492039") # => true
sleep 30
totp.verify("492039") # => falsehotp = ROTP::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) # => falseROTP::Base32.random_base32 # returns a 16 character base32 secret. Compatible with Google AuthenticatorNote: The Base32 format conforms to RFC 4648 Base32
Provisioning URI's generated by ROTP are compatible with the Google Authenticator App to be scanned with the in-built QR Code scanner.
totp.provisioning_uri("[email protected]") # => 'otpauth://totp/[email protected]?secret=JBSWY3DPEHPK3PXP'
hotp.provisioning_uri("[email protected]", 0) # => 'otpauth://hotp/[email protected]?secret=JBSWY3DPEHPK3PXP&counter=0'This can then be rendered as a QR Code which can then be scanned and added to the users list of OTP credentials.
Scan the following barcode with your phone, using Google Authenticator
Now run the following and compare the output
require 'rubygems'
require 'rotp'
totp = ROTP::TOTP.new("JBSWY3DPEHPK3PXP")
p "Current OTP: #{totp.now}"bundle install
bundle exec rspecOnce the rotp rubygem is installed on your system, you should be able to run the rotp executable
(if not, you might find trouble-shooting help at this stackoverflow question).
# Try this to get an overview of the commands
rotp --help
# Examples
rotp --secret p4ssword # Generates a time-based one-time password
rotp --hmac --secret p4ssword --counter 42 # Generates a counter-based one-time passwordHave a look at the contributors graph on Github.
MIT Copyright (C) 2011 by Mark Percival, see LICENSE for details.
A list can be found at Wikipedia.