laravel - 使用身份验证尝试时出现问题
问题描述
在将问题带到这里之前,我真的尝试自己调试我的问题,但是我真的找不到解决我的 laravel 身份验证问题的方法,尽管这似乎是一个常见问题。
我的身份验证不会登录。它总是返回 false,我不明白为什么。
我正在尝试使用 auth:attempt 登录,但它不起作用。总是在其他情况下。
当 auth 尝试获得成功时,如果条件其他条件,它会自动进入
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Redirect;
use App\User;
use Illuminate\Support\Facades\Auth;
class AdminCreateLogin extends Controller
{
public function addAdmin(Request $request)
{
$name = $request->username;
$password = $request->password;
$password = Hash::make($password);
$email = $request->email;
$user= new User;
$user->name = $name;
$user->password = $password;
$user->email = $email;
$user->save();
}
public function adminLogin(Request $request)
{
$email = $request->email;
$password1 = $request->password;
$password = bcrypt($password1);
//$password = hash:make($password1);
$userdata = array(
'email' => $email,
'password' => $password
);
if(Auth::attempt($userdata))
{
echo "login";
die;
return redirect('/admin/post/list');
}
else
{
echo "login not";
die;
return back()->with('error',"Invalid Login");
}
}
}
请帮助我。
解决方案
你不需要bcrypt
手动。https://laravel.com/docs/7.x/authentication#authenticating-users
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
// Authentication passed...
return redirect()->intended('dashboard');
}
推荐阅读
- c++ - 使用双指针和递归的单链表反转
- java - 如何找到两个不同数组(双精度和整数)的平均值
- python - 如何使用 python 连接 Aurora PostgreSQL 无服务器实例?
- flutter - Flutter:添加原生代码【Payfort 支付】
- java - 使用 thymeleaf 和自定义内容类型渲染视图
- asp.net-mvc - Blazor 服务器 - 未处理异常的全局日志记录
- php - 如何使用 PHP 将图像上传到谷歌“按图像搜索”?
- java - 有没有办法根据用户输入创建页面/活动或类似的东西?
- python - Moviepy 子剪辑在最后捕获了额外的 4 秒
- javascript - 关于产品变体描述