I don't think you need to hash the password before using Auth::attempt()
thepsion5 said:
I don't think you need to hash the password before using
Auth::attempt()
Thanks for the reply Sir. I tried also to remove it by using this code
$credentials = [
'email' => Input::get('email'),
'password' => Input::get('password')
];
if(Auth::attempt($credentials)) {
return 'success';
}else {
return 'auth failed';
}
but it doesn't fixed the error.
Make sure that your password column on your users table is long enough, it's possible the passwords are getting cut off. See this topic: http://laravel.io/forum/04-17-2014-hashcheck-nor-hashattempt-match-with-original-password
After making your column long enough you'll need to re-register your users (or manually update their password hash).
My password has a limit of 255 characters, yes I tried to delete and re-register my user but the error is still there.
I had the same problem, but i couldn't find a solution, instead i ran the query to check for credentials, and then i forced login.
$auth = User::where('Username', '=', Input::get('username'))->where('Password', '=', Hash::make(Input::get('password')))->first();
if($auth){
Auth::login($auth);
}
return Redirect::intended('home');
}
Joe96 said:
I had the same problem, but i couldn't find a solution, instead i ran the query to check for credentials, and then i forced login.
$auth = User::where('Username', '=', Input::get('username'))->where('Password', '=', Hash::make(Input::get('password')))->first(); if($auth){ Auth::login($auth); } return Redirect::intended('home'); }
Thanks for the tips but when I tried to use your code
$auth = User::where('email', '=', Input::get('email'))->where('Password', '=', Hash::make(Input::get('password')))->first();
if($auth){
Auth::login($auth);
return Redirect::intended('submit');
}else {
return 'auth failed';
}
still I am receiving auth failed
Nevermind, I see the problem, the problem is with your registration. You're not storing the password in a hashed form, you're hashing the password to validate it (it should be validated in its original form) and then hashed for storage.
$data = array(
'email' => Input::get('email'),
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'password' => Hash::make($password)
);
Should be:
$data = array(
'email' => Input::get('email'),
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'password' => Input::get('password')
);
And this:
$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->email = Input::get('email');
$user->password = Input::get('password');
$user->save();
Should be:
$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
citricsquid said:
helmikuu27 said: still I am receiving auth failed
Are you absolutely sure that the password is correct? Do the following:
echo Hash::make('password-here');
Then compare the result against the hash stored in your database, see if they match.
Thank you very much! This suggestion gave me an idea how to use the Hash::make function. The error is fixed by hashing the password before storing it into database and do the basic validation on my controller. I learn a lot today. Thanks again. :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community