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?

chetu
  • 245
  • 3
  • 15

4 Answers4

2

I think you can do it like this:

class User < ActiveRecord::Base
  acts_as_authentic do |config|
    config.validate_password_field = false
  end
end
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
1

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
  • 9,616
  • 6
  • 50
  • 64
  • 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 Feb 01 '10 at 16:51
1

I had the same issue with the authlogic_ldap addon that I modified for my app. I make the mistake of including login_field :ldap_login in the User class. I also had a stack level too deep error initially, but I reverted authlogic from v3.0.3 to v3.0.2 and it works now.

Jon Bramble
  • 326
  • 3
  • 6
0

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
  • 7,681
  • 3
  • 37
  • 38
  • 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 Jan 05 '10 at 00:41
  • It still says "Password can not be blank" even though I didn't provide a password field on the UI. – chetu Jan 06 '10 at 18:37
  • 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 Jan 06 '10 at 19:22
  • 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 Jan 15 '10 at 04:28