Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8673691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:31:23+00:00 2026-06-12T19:31:23+00:00

I need to write a log when somebody failes to log in to my

  • 0

I need to write a log when somebody failes to log in to my app (to track bruteforce attempts). Also I decided to log successful authentications.
So I created a SessionsController < Devise::SessionsController and tried to override the sessions#create method like that: https://gist.github.com/3884693

The first part works perfectly, but when the auth failes rails throws some kind of an exception and never reaches the if statement. So I don’t know what to do.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:31:25+00:00Added an answer on June 12, 2026 at 7:31 pm

    This answer to a previous SO question – Devise: Registering log in attempts has the answer.

    The create action in the devise controller calls warden.authenticate!, which attempts to authenticate the user with the supplied params. If authentication fails then authenticate! will call the devise failure app, which then runs the SessionsController#new action. Note, any filters you have for the create action will not run if authentication fails.

    So the solution is to add a filter after the new action which checks the contents of env["warden.options"] and takes the appropriate action.

    I tried out the suggestion, and was able to log both the successful & failed login attempts. Here is the relevant controller code:

    class SessionsController < Devise::SessionsController
      after_filter :log_failed_login, :only => :new
    
      def create
        super
        ::Rails.logger.info "\n***\nSuccessful login with email_id : #{request.filtered_parameters["user"]}\n***\n"
      end
    
      private
      def log_failed_login
        ::Rails.logger.info "\n***\nFailed login with email_id : #{request.filtered_parameters["user"]}\n***\n" if failed_login?
      end 
    
      def failed_login?
        (options = env["warden.options"]) && options[:action] == "unauthenticated"
      end 
    end
    

    The log has the following entries:

    For a successful login

    Started POST "/users/sign_in"
    ...
    ...
    ***
    Successful login with email_id : {"email"=>...
    ***
    ...
    ...
    Completed 302 Found
    

    For a failed login

    Started POST "/users/sign_in"
    ...
    ...
    Completed 401 Unauthorized 
    Processing by SessionsController#new as HTML
    ...
    ...
    ***
    Failed login with email_id : {"email"=>...
    ***
    ...
    ...
    Completed 302 Found
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´m trying to write a log system for my CakePHP intranet. What i need
I need to write an app to playback a DICOM multiframe image. Each frame
I need to write small a log analyzer application to process some log files
let's say I have 10 tables and I need to write a simple LOG
I need to write to a particular log file, and append the results of
I need to write an error log to a XML file using Visual Basic
I need to write some system log data (usually not more than 100 characters
I need to write the actual user thread ID to a log file. If
I'm writing an app (C#) and at times I will need to log to
In an application I'm working on, I need a write-behind data log. That is,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.