使用身份验证尝试时出现问题
Getting issue when auth attempt used
我真的尝试自己调试我的问题,然后再将它们带到这里,但我真的找不到解决我的 laravel 身份验证问题的方法,尽管它似乎是一个常见问题。
我的身份验证无法登录。它总是 returns 错误,我不明白为什么。
我正在尝试使用 auth:attempt 登录,但它不起作用。总是处于其他状态。
当 auth 尝试获得成功时,它会自动进入 if 条件否则其他条件
<?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');
}
我真的尝试自己调试我的问题,然后再将它们带到这里,但我真的找不到解决我的 laravel 身份验证问题的方法,尽管它似乎是一个常见问题。
我的身份验证无法登录。它总是 returns 错误,我不明白为什么。
我正在尝试使用 auth:attempt 登录,但它不起作用。总是处于其他状态。
当 auth 尝试获得成功时,它会自动进入 if 条件否则其他条件
<?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');
}