Search code examples
rubyauthenticationweb-applicationscamping

authentication fails in camping web app after attribute update


I have a problem with my Camping app for which I've setup an authentication system based on this (http://nycda.com/blog/basic-user-authentication-model-in-rails-4/) tutorial.

I wanted to learn how to setup such a system from scratch to better understand the underlying logic. With this system in place users can create their accounts and login and logout without problems and authentications pass.

It took me a while to determine that the problem with authentication occurs after the user role has been updated in the database. Every user has a default role upon registration, which managers can change after registration. And after that the user authentication fails.

Prior to that there are no errors and users can navigate the application. If I inspect the database I see the user role being updated.

Is the problem related to the database update?

I'm using camping with bcrypt and activerecord 4.0.4. Please see this gist: camping auth

Thank you for your help.

Regards, seba


Solution

  • Having only briefly looked through the code, I'd guess that updating the role is causing the password hash to be recreated because the logic in the encrypt_password message doesn't appear to prevent that from happening.

    You could verify this by seeing if the hash in the DB changes between creation and role update. To prevent this, you could try wrapping that code in an "unless password.nil?" condition in that method.

    Hope this helps.