Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a user's password is correct without logging them in with Devise?

I'm programming a timeclock system where a user effectively punches their timeclock by entering their username and password in a specific computer. A timeclock user will first login. I just need to register that a user showed up by checking if the username and password they entered is correct. How can I do that in Devise?

I don't want to actually log them in, only check that they are who they say they are. The timeclock user is the only user logged in at all times.

like image 200
at. Avatar asked Feb 26 '13 02:02

at.


People also ask

What if the password or user account is not correct?

Note: If the password or user account is not correct, it will produce an error with the code 1326: the username or password is incorrect. This process is basically the same as described in method one, but this time, via the GUI.

How do I check if a user's password is valid?

Check a user's password against the organization's password validation policy and report whether the password is valid. Use this action to provide real-time feedback on password strength while the user types their password. One of the following permissions is required to call this API.

What is a password checker?

Password checker program basically checks if the password is valid or not based on password policies mention below: Password should not contain any space. Password should contain at least one digit (0-9). Password length should be between 8 to 15 characters. Password should contain at least one lowercase letter (a-z).

How to test if a credential is locked out?

Testing a credential for the existence of an account would be a matter of using net user or dsquery. The net user command won't tell you if an account is locked out, but querying the lockoutTime attribute of the user account could tell you that.


2 Answers

If you use gem devise. Try

User.find(1).valid_password?('password123')  # returns true/false

That code in file: devise/lib/devise/models/database_authenticatable.rb

like image 149
azhao Avatar answered Oct 20 '22 00:10

azhao


Use Devise Methods

Devise gives you two built-in methods that let you do exactly this:

user = User.find_for_authentication(username: params[:username])
user.valid_password?(params[:password])
like image 28
Sheharyar Avatar answered Oct 20 '22 00:10

Sheharyar