I have a User Model with encryption using brcypt gem.
However, when I am using the following code it is returning false as result.
User.find(117).try(:authenticate ,User.find(117).password_digest)
But below mentioned command works fine:
User.find(117).try(:authenticate ,"password")
It returns true.
So how can I achieve the first conditions when I need to validate the password already stored in the database.
Any help would be appreciated!!
In you first line you pass the digested password, that (depending on your implementation or gem you are using) should be an one-way encrypted string from the original password. You have no way to verify this digest without the original password.
While
try
is a great thing, it hides away all useful errors you could get. Your code would be better if you split up finding the user and authenticating the password.