I am getting quite desperate with Laravel 5.4 and Eloquent Query builder. I am trying to retrieve a user by username and password.
I ve following columns in my db: ID, USERNAME, PASSWORD
Following query is working for me:
$user = UserModel::where(['username' => $username])->first();
while this one is not:
$user = UserModel::where(['password' => $password])->first();
I am printing out both $username
and $password
before the query, and both are exactly what they should be.
What can i possibly do wrong?
EDIT:
I tried following forms of queries with same results:
$user = UserModel::where('password', $password)->first();
$user = UserModel::where(['password' => $password])->first();
$user = UserModel::where('password', '=', $password)->first();
Variations with username lead to exactly same results as in the first one mentioned.
Problem solved althought i am not exactly sure what caused it. Problem was, that Eloquent with oci8 driver (oracle driver) converts all column names to uppercase, but 'password' is some kind of reserved keyword and could not be converted and stayed in lowercase. While Oracle is case sensitive (for column and table names) it was not working. i changed name of 'password' column to 'passphrase' and everything worked immediately.
The passwords are not saved in plain text so you must hash input first
$password = Hash::make('plaintext');
$result = User::wherePassword($password)->first();