Search code examples
phplaravellaravel-5lumenlumen-5.3

lumen hash check return always false


I'm using Lumen to develop my API website, I came across this part where I hash password and check hash but it always returns false below is my attempt.

$hashed = $request->input('hash'); // e.g. $2y$10$EBQKLl5cdbOLzP0luWUlp.hQYJLYGnDeOymodXSAbWj.Posf.yv1m
$res = Hash::check(trim($request->input('password')), trim($hashed));

return response()->json([ 'hash' => $hashed, 'password' => $request->input('password')), 'hash_result' => $res ]);

I use trim so to make sure there are not whitespaces and I can verify variables (hash, password) exist so what seem's wrong?

using postman

enter image description here

Any help, ideas is greatly appreciated. Thank you.


Solution

  • hash::check() is for checking a plain text(like password) against a hash witch has been generated inside your website. there is a key in .env named "APP_KEY" witch is used to create the hash and checking the hash.

    so what you are doing wrong is sending the password and hashed password(witch is not generated by your website) in the same request to your API.

    just send the password and check it against the hashed version in your DB.