use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
public function login(Request $request)
{
$user = User::where('email', $request->email)
->where('password',md5($request->password))
->firstOrFail();
Auth::login($user);
return redirect('/');
}
You changed it in the query for logging in there, but did you change it where the user is created, where the password initially gets encrypted with bcrypt() and stored in the db?
Otherwise you're comparing a md5 hash to a bcrypt hash in the db.
Why are you doing this though? md5 should never be used for password hashes. They're very insecure. bcrypt() is far superior.
Why are common hashing functions such as md5() and sha1() unsuitable for passwords?
Hashing algorithms such as MD5, SHA1 and SHA256 are designed to be very fast and efficient. With modern techniques and computer equipment, it has become trivial to "brute force" the output of these algorithms, in order to determine the original input. Because of how quickly a modern computer can "reverse" these hashing algorithms, many security professionals strongly suggest against their use for password hashing.
Show your code where the user gets created, like where they sign up...
And you probably get that error because you use firstOrFail(). If it doesn't find the user where the email and password match, it fails, so if you're entering the wrong password, that's why.
No, the user doesn't get created there... It would be the RegisterController where it creates the user and saves them in the database when they sign up...
I don't know what YOU want to do. What do you want it to do when it can't find the user when they try to login? The default auth system redirects back to the form and displays the error messages, just like with all forms.
Obviously if it can't find the user, you can't do Auth::login($user); as $user will be null.