tags:

views:

331

answers:

3

I am creating an application for which I am trying to use LDAP with authlogic for login authentication. I want to accept just the username and log the user in if he is on the LDAP server. For this, I need to disable the password validation. How can I do that?

A: 

I was successful doing this with Open ID (same idea, password not stored by my app) by not having a password column in the users table and using this config for Authlogic:

class User < ActiveRecord::Base
  acts_as_authentic do |c|
    c.crypted_password_field = false
  end
end

Without setting crypted_password_field, there were errors generated during user saves.

Sean Carpenter
I tried it but it didn't work for me. Prior to this I used authlogic-openid gem to create a login which doesn't require password.I refered to this screencast: http://railscasts.com/episodes/160-authlogic
chetu
What didn't work? Were there errors generated?
Sean Carpenter
It still says "Password can not be blank" even though I didn't provide a password field on the UI.
chetu
You need to make sure there is no password field in the `users` table (or whatever table underlies your `acts_as_authentic` model). This is what generates a password attribute on the model.
Sean Carpenter
My user model doesn't have password field but still it gives me the same error message. I feel like password is required in authlogic gem.
chetu
+1  A: 

In your User model where you call acts_as_authentic, this might do the trick:

acts_as_authentic do |config|
  config.require_password_confirmation = false
  config.ignore_blank_passwords = true
end

These config options, among others, can be found in lib/authlogic/acts_as_authentic/password.rb (in version 2.1.3).

Eliot Sykes
I tried that too but didn't work. I looked in the source code for authlogic and it looks like UserSession model still needs password when it tries to save it.
chetu
A: 

I think you can do it like this:

class User < ActiveRecord::Base
  acts_as_authentic do |config|
    config.validate_password_field = false
  end
end
J. Pablo Fernández