Giter Club home page Giter Club logo

two_factor_authentication's Introduction

Two factor authentication for Devise

Features

  • control sms code pattern
  • configure max login attempts
  • per user level control if he really need two factor authentication
  • your own sms logic

Configuration

Initial Setup

In a Rails environment, require the gem in your Gemfile:

gem 'two_factor_authentication'

Once that's done, run:

bundle install

Automatic installation

In order to add two factor authorisation to a model, run the command:

bundle exec rails g two_factor_authentication MODEL

Where MODEL is your model name (e.g. User or Admin). This generator will add :two_factor_authenticatable to your model and create a migration in db/migrate/, which will add ::second_factor_pass_code and :second_factor_attempts_count to your table. Finally, run the migration with:

bundle exec rake db:migrate

Manual installation

To manually enable two factor authentication for the User model, you should add two_factor_authentication to your devise line, like:

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :two_factor_authenticatable

Two default parameters

  config.login_code_random_pattern = /\w+/
  config.max_login_attempts = 3

Possible random patterns

/\d{5}/
/\w{4,8}/

see more https://github.com/benburkert/randexp

Customisation

By default second factor authentication enabled for each user, you can change it with this method in your User model:

  def need_two_factor_authentication?(request)
    request.ip != '127.0.0.1'
  end

this will disable two factor authentication for local users

Your send sms logic should be in this method in your User model:

  def send_two_factor_authentication_code(code)
    puts code
  end

This example just puts the code in the logs.

External dependencies

Randexp requires words files (Check if it is installed in /usr/share/dict/words or /usr/dict/words), you might need install it:

apt-get install wbritish # or whichever you require

two_factor_authentication's People

Contributors

carvil avatar houdini avatar wkrsz avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.