README.md in rotp-4.0.2 vs README.md in rotp-4.1.0

- old
+ new

@@ -1,9 +1,10 @@ # The Ruby One Time Password Library [![Build Status](https://travis-ci.org/mdp/rotp.svg?branch=master)](https://travis-ci.org/mdp/rotp) [![Gem Version](https://badge.fury.io/rb/rotp.svg)](https://rubygems.org/gems/rotp) +[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/github/mdp/rotp/master) [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/mdp/rotp/blob/master/LICENSE) A ruby library for generating and validating one time passwords (HOTP & TOTP) according to [RFC 4226](http://tools.ietf.org/html/rfc4226) and [RFC 6238](http://tools.ietf.org/html/rfc6238). ROTP is compatible with [Google Authenticator](https://github.com/google/google-authenticator) available for [Android](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2) and [iPhone](https://itunes.apple.com/en/app/google-authenticator/id388497605) and any other TOTP based implementations. @@ -70,18 +71,21 @@ ```ruby 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 reused the OTP inside the 30s window + +# 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 ``` ### Verifying a Time based OTP with drift @@ -113,12 +117,15 @@ Provisioning URI's generated by ROTP are compatible with most One Time Password applications, including Google Authenticator. ```ruby -totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/issuer:alice@google.com?secret=JBSWY3DPEHPK3PXP' -hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/issuer:alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=0' +totp = ROTP::TOTP.new("base32secret3232", issuer: "My Service") +totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/My%20Service:alice@google.com?secret=base32secret3232&issuer=My+Service' + +hotp = ROTP::HOTP.new("base32secret3232", issuer: "My Service") +hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/alice@google.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. #### Working example @@ -141,10 +148,20 @@ ```bash bundle install bundle exec rspec ``` +### Testign with Docker + +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 + +```bash +docker build -f Dockerfile-2.6 -t rotp_2.6 . +docker run --rm -v $(pwd):/usr/src/app rotp_2.6 +``` + ## Executable Usage The rotp rubygem includes an executable for helping with testing and debugging ```bash @@ -160,10 +177,10 @@ Have a look at the [contributors graph](https://github.com/mdp/rotp/graphs/contributors) on Github. ## License -MIT Copyright (C) 2016 by Mark Percival, see [LICENSE](https://github.com/mdp/rotp/blob/master/LICENSE) for details. +MIT Copyright (C) 2019 by Mark Percival, see [LICENSE](https://github.com/mdp/rotp/blob/master/LICENSE) for details. ## Other implementations A list can be found at [Wikipedia](https://en.wikipedia.org/wiki/Google_Authenticator#Implementations).