I have a User model that can save two types of users:
Password-protected users (for this I need has_secure_password)
Facebook users (for this I don’t need has_secure_password, but two different fields: provider and uid)
So, when a normal user registers, the model should validate password fields with has_secure_password and validate the presence of the password field:
But when a user wants to register through Facebook, the password is not needed, because provider and uid will be filled instead. The problem is that I don’t know how to disable has_secure_password in this case. I have tried this:
This does not work with has_secure_password because this module
automatically adds this validation:
validates_presence_of :password_digest
so no matter how you change the condition of validation in your own
model it just doesnt work. The solution I can think of is to write
your own has_secure_password module, you can copy a lot code from the
original from rails. Or use devise instead.
I also have dual login types (ldap and manual, the latter using
has_secure_password) and had the same problem.
It might seem like a hack but the simple solution was to just
set a bogus password for the ldap users (in the create method
in my controller). I don't see any security problem with this
since the ldap users cannot login manually using that password.