Git Product home page Git Product logo

Comments (6)

mattcg avatar mattcg commented on July 20, 2024 4

It's possible to display a specific message when only the authentication code is incorrect with a few changes to your model and the Devise language configuration file.

#app/models/user.rb
#...

  def unauthenticated_message
    if @failed_otp
      :invalid_otp
    else
      super
    end
  end

  def validate_and_consume_otp!(code, options = {})
    @failed_otp = !super(code, options)
    return !@failed_otp
  end

  private

  @failed_otp = false

#...
#config/locales/devise.en.yml

en:
  devise:
    failure:
      invalid_otp: "Invalid authentication code."

from devise-two-factor.

ZempTime avatar ZempTime commented on July 20, 2024 1

in config/locales/devise.en.yml you can set the majority of the message Devise uses.

to do authentication on login specifically, look for the invalid entry, and change it something like this:

en:
  devise:
    failure:
      invalid: "Invalid %{authentication_keys}, one-time-use code, or password."

from devise-two-factor.

I-Iugo avatar I-Iugo commented on July 20, 2024

+1

from devise-two-factor.

mattcg avatar mattcg commented on July 20, 2024

@ZempTime that is helpful, but I don't think it works around the original issue, which is that it should be possible for a specific message to be shown when the authentication is invalid but the username and password are valid.

from devise-two-factor.

thiagosf avatar thiagosf commented on July 20, 2024

@mattcg perfect to my situation! I added a little bit:

def unauthenticated_message
  if @failed_otp
    :invalid_otp
  elsif self.otp_required_for_login
    :required_otp
  else
    super
  end
end

from devise-two-factor.

QuinnWilton avatar QuinnWilton commented on July 20, 2024

This is a perfectly valid use-case, but it's worth keeping in mind the usability / security trade-off that's being made. More specific messages are helpful to the user, but they also provide more information to an attacker.

For example, depending on what error messages you use, an attacker that compares a leaked username / password list from another site against your login form will either gain no information about whether the user exists, or they will learn that the user does exist, and that they shared their password across the two sites. From there, they might opt to perform a more targeted attack against the user.

Whether that's something you're concerned with is up for debate, but it's worth remembering when deciding to provide more detailed error messages.

from devise-two-factor.

Related Issues (20)

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.