Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
3,489 | 2 months ago | 78 | mit | Python | ||||||
Bruteforce attack for Instagram | ||||||||||
Rotp | 1,524 | 2,527 | 63 | a month ago | 38 | December 13, 2022 | 3 | mit | Ruby | |
Ruby One Time Password library | ||||||||||
Ios Application | 919 | 2 months ago | 65 | other | Swift | |||||
A native, lightweight and secure one-time-password (OTP) client built for iOS; Raivo OTP! | ||||||||||
Notp | 662 | 169 | 65 | 4 months ago | 5 | October 14, 2014 | 22 | mit | JavaScript | |
Node One Time Password library, supports HOTP, TOTP and works with Google Authenticator | ||||||||||
Onetimepass | 647 | 62 | 5 | 2 years ago | 6 | July 31, 2015 | 10 | mit | Python | |
One-time password library for HMAC-based (HOTP) and time-based (TOTP) passwords | ||||||||||
50m_ctf_writeup | 542 | 5 years ago | 1 | |||||||
$50 Million CTF from Hackerone - Writeup | ||||||||||
Java Otp | 361 | 1 | a year ago | 5 | July 31, 2022 | mit | Java | |||
A one-time password (HOTP/TOTP) library for Java | ||||||||||
Gotp | 348 | 3 | 34 | a year ago | 1 | September 15, 2022 | mit | Go | ||
Golang OTP(One-Time Password) Library. | ||||||||||
Nimble_totp | 347 | 1 | 7 days ago | 5 | May 02, 2022 | 1 | Elixir | |||
A tiny Elixir library for time-based one time passwords (TOTP) | ||||||||||
Java Totp | 163 | 2 years ago | 10 | November 05, 2020 | 13 | mit | Java | |||
A java library for implementing Time-based One Time Passwords for Multi-Factor Authentication. |
Although this library will continue to be maintained, if you're implementing a 2FA solution today, you should take a look at Webauthn. It doesn't involve shared secrets and it's supported by most modern browsers and operating systems.
A ruby library for generating and validating one time passwords (HOTP & TOTP) according to RFC 4226 and RFC 6238.
ROTP is compatible with Google Authenticator available for Android and iPhone and any other TOTP based implementations.
Many websites use this for multi-factor authentication, such as GMail, Facebook, Amazon EC2, WordPress, and Salesforce. You can find a more complete list here.
ROTP::Base32.random_base32
is now ROTP::Base32.random
and the argument
has changed from secret string length to byte length to allow for more
precision. There is an alias to allow for random_base32
for the time being.verify
now takes options for drift
and after
,padding
is no longer an optionverify
returns a timestamp if true, nil if falsegem install rotp
totp = ROTP::TOTP.new("base32secret3232", issuer: "My Service")
totp.now # => "492039"
# OTP verified for current time - returns timestamp of the current interval
# period.
totp.verify("492039") # => 1474590700
sleep 30
# OTP fails to verify - returns nil
totp.verify("492039") # => nil
hotp = ROTP::HOTP.new("base32secretkey3232")
hotp.at(0) # => "786922"
hotp.at(1) # => "595254"
hotp.at(1401) # => "259769"
# OTP verified with a counter
hotp.verify("259769", 1401) # => 1401
hotp.verify("259769", 1402) # => nil
By keeping track of the last time a user's OTP was verified, we can prevent token reuse during the interval window (default 30 seconds)
The following is an example of this in action:
user = User.find(someUserID)
totp = ROTP::TOTP.new(user.otp_secret)
totp.now # => "492039"
# Let's take a look at the last time the user authenticated with an OTP
user.last_otp_at # => 1432703530
# Verify the OTP
last_otp_at = totp.verify("492039", after: user.last_otp_at) #=> 1472145760
# ROTP returns the timestamp(int) of the current period
# Store this on the user's account
user.update(last_otp_at: last_otp_at)
# Someone attempts to reuse the OTP inside the 30s window
last_otp_at = totp.verify("492039", after: user.last_otp_at) #=> nil
# It fails to verify because we are still in the same 30s interval window
Some users may enter a code just after it has expired. By adding 'drift' you can allow for a recently expired token to remain valid.
totp = ROTP::TOTP.new("base32secret3232")
now = Time.at(1474590600) #2016-09-23 00:30:00 UTC
totp.at(now) # => "250939"
# OTP verified for current time along with 15 seconds earlier
# ie. User enters a code just after it expired
totp.verify("250939", drift_behind: 15, at: now + 35) # => 1474590600
# User waits too long. Fails to validate previous OTP
totp.verify("250939", drift_behind: 15, at: now + 45) # => nil
ROTP::Base32.random # returns a 160 bit (32 character) base32 secret. Compatible with Google Authenticator
Note: The Base32 format conforms to RFC 4648 Base32
Provisioning URI's generated by ROTP are compatible with most One Time Password applications, including Google Authenticator.
totp = ROTP::TOTP.new("base32secret3232", issuer: "My Service")
totp.provisioning_uri("[email protected]") # => 'otpauth://totp/My%20Service:alice%40google.com?secret=base32secret3232&issuer=My%20Service'
hotp = ROTP::HOTP.new("base32secret3232", issuer: "My Service")
hotp.provisioning_uri("[email protected]", 0) # => 'otpauth://hotp/alice%40google.com?secret=base32secret3232&counter=0'
This can then be rendered as a QR Code which the user can scan using their mobile phone and the appropriate application.
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 rspec
In order to make it easier to test against different ruby version, ROTP comes with a set of Dockerfiles for each version that we test against in Travis
docker build -f Dockerfile-2.6 -t rotp_2.6 .
docker run --rm -v $(pwd):/usr/src/app rotp_2.6
Alternately, you may use docker-compose to run all the tests:
docker-compose up
The rotp rubygem includes CLI version to help with testing and debugging
# 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 password
Have a look at the contributors graph on Github.
MIT Copyright (C) 2019 by Mark Percival, see LICENSE for details.
A list can be found at Wikipedia.