This Gem can be used to create 2FA (Two-Factor Authentication) function, email address verification function for member registration and etc in Ruby on Rails.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install one_time_password
Run command for an installation.
bundle exec rails g one_time_password:install
The following events will take place when using the install generator:
- An initializer file will be created at
- A migration file will be created at
- A model file will be created at
And run migration.
bundle exec rails db:migrate
CONTEXTS in initializer settings.
FUNCTION_NAMES: Using function_name in OneTimeAuthentication Model enum.
Hash, one of
|function_name (Symbol)||Name each function.|
|expires_in (ActiveSupport::Duration)||Password validity time.|
|max_authenticate_password_count (Integer)||Number of times user can enter password each generated password.|
|password_length (Integer)||Password length. At 6, for example, the password would be 123456.|
|If you try to authenticate with the wrong password a password_failed_limit times within the time set by password_failed_period, you will not be able to generate a new password.|
See example and its sequence diagram
For more information, see the implementation of OneTimePassword :: OneTimeAuthenticationModel.
Example and its sequence diagram
See sign up exsample.
The gem is available as open source under the terms of the MIT License.