[英]Laravel Auth::attempt not authenticating
Auth::attempt doesn't validate. Auth::attempt 不验证。 I am using a custom controller to register and login users for learning purposes
我正在使用自定义 controller 注册和登录用户以用于学习目的
My Controller that creates and logins user我的 Controller 创建和登录用户
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
use App\User;
class UsersController extends Controller
{
public function login(){
return view('login');
}
public function register(){
return view('register');
}
public function create_user(Request $request){
$this->validate($request,[
'name' => 'required',
'email' => 'required',
'password' => 'required|confirmed'
]);
$password = Hash::make('password');
User::create([
'name' => request('name'),
'email' => request('email'),
'password' => $password
]);
return redirect('/login');
}
public function validate_login(Request $request){
if(Auth::attempt(['email'=>request('email'),'password'=>request('password')])){
return 'exitsts';
}else{
return 'doesnt exist';
}
}
}
My Login View我的登录视图
<form action="login" method="POST">
@csrf
<input type="text" name="email">
<input type="password" name="password">
<input type="submit">
</form>
So as you can see the passwords are hashed using Hash::make()如您所见,密码使用 Hash::make() 进行哈希处理
Ps already seen: ps已经看过了:
Laravel Auth::atempt keeps failing Laravel Auth::attempt 不断失败
Can't authenticate user with Laravel Auth::Atempt 无法使用 Laravel Auth::Attemp 验证用户
Laravel auth::atempt get only hashed password Laravel auth::attempt get only hashed password
Laravel - can't get auth::atempt to work properly Laravel - 无法获得 auth::尝试正常工作
Using使用
$password = bcrypt(request('password'));
in my register function worked, instead of using在我的寄存器 function 工作,而不是使用
$password = Hash::make(request('password'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.