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

  • Home
  • SEARCH
  • 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 8821723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:55:35+00:00 2026-06-14T05:55:35+00:00

I am trying to rewrite an older app that was created with PHP/MySQL. The

  • 0

I am trying to rewrite an older app that was created with PHP/MySQL.
The authentication system used has a users table in the database that stores username, email etc… but NOT passwords.

Whenever the user logs in it first checks the database to see if the user exists if not then returns a login error. If the user exists in the local database then it tries to bind to the active directory using the username/password combination entered by the user and creates a session if successful.

What is the best way to accomplish this using Rails?

  • 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-14T05:55:36+00:00Added an answer on June 14, 2026 at 5:55 am

    Ruby’s Net::LDAP library is pretty good.

    Here’s a simplified version of what I’ve been using for years:

    # sessions_controller.rb
    def create
      user = User.find_by_login(params[:login])
      if user && Ldap.authenticate(params[:login], params[:password])
        self.current_user = user
        Rails.logger.info "Logged in #{user.name}"
        flash[:notice] = "Successfully Logged In!"
        redirect_back_or_default root_url
      else
        flash[:alert] = "Invalid User credentials"
        render :new
      end
    end
    
    # lib/ldap.rb
    # Ldap.authenticate('user','password')
    # Returns true if validated
    # Returns false if invalidated
    # Returns nil if LDAP unavailable
    require 'net/ldap'
    class Ldap
      def self.config
        # this is actually loaded from a yaml config file
        {
          :domain => 'YOURDOMAIN',
          :host   => '10.10.10.100'
        }
      end
    
      def self.authenticate(login, password)
        conn = Net::LDAP.new(
          :host       => config[:host],
          :port       => 636,
          :base       => "dc=#{config[:domain]}, dc=local",
          :encryption => :simple_tls,
          :auth       => {
            :username => "#{login}@#{config[:domain]}.local",
            :password => password,
            :method   => :simple
          }
        )
        Timeout::timeout(15) do
          return conn.bind ? true : false
        end
      rescue Net::LDAP::LdapError => e
        notify_ldap_admin(config[:host],'Error',e)
        nil
      rescue Timeout::Error => e
        notify_ldap_admin(config[:host],'Timeout',e)
        nil
      end
    
      def self.notify_ldap_admin(host,error_type,error)
        msg = "LDAP #{error_type} on #{host}"
        RAILS_DEFAULT_LOGGER.debug(msg)
        DeveloperMailer.deliver_ldap_failure_msg(msg,error)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to rewrite a url so that all requests for /admin get
I'm trying to rewrite a url of this: http://www.foo.com/bar/baz to index.php?q=$1&d=baz Where bar is
I am trying to rewrite mysite.com/broadcasts to mysite.com/feed so that it will show up
We are trying to rewrite an IIS web server handler for JBoss 5 app
I am trying to rewrite this messy code, so that I only make one
I am trying to rewrite all URIs inside directory /docs to /docs/index.php, using apaches
I'm trying to sort out a result set that gives the 5 closest users
I have an older form that I really don't want to rewrite at this
I'm trying rewrite game guess word from C# console to C# windows form, and
Trying to rewrite machine generated my first ever WP7 HelloWorld into something more sophisticated.

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.