我试图使用Laravel
登录但是我遇到了一些问题
这就是我保存用户的方式:
$user = User::create(array('email'=> $_REQUEST['email'], 'password' => encrypt($password), 'firstname'=> $_REQUEST['firstname'], 'lastname'=>$_REQUEST['lastname'], 'unecrypted'=> $password));
现在你可以看到我使用encrypt($password)
这在我的数据库中创建了以下记录:
'39', '[email protected]', 'eyJpdiI6Iis5RTRQdjBCV1piSVEwN0ZwRDQxa1E9PSIsInZhbHVlIjoiTnY1UnJ0YkVqZkY0VlhzdWhBK1QzUWxIdTc0SXNBRHlPcHQrcXpicmZHND0iLCJtYWMiOiJhODM2ZDI4ZTE5ZjY5YjlkNmQyOGIyYTdiOTU3NzFkNmNmZWNlOGVhMDNjYjY0ZTFiZjZiOGJlNWM3N2U4MmViIn0=', '2018-01-01 13:45:51', '2018-01-01 13:45:51', NULL, 'Marc', 'Rasmussen'
哪个看起来正确。
然后我有以下LoginController
:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
但是,当我尝试使用我的密码登录时(我知道这是正确的)我收到以下消息:
These credentials do not match our records.
谁能看到我做错了什么?
使用bcrypt()
帮助程序加密密码:
'password' => bcrypt($password),
如果你想使用自己的密码加密方法,你不要使用laravel的内置Auth功能Becuase laravel Auth匹配密码只有通过bcrypt方法加密的密码,如bcrypt($password);
如果您想使用自己的加密方法,则需要覆盖Auth登录功能并创建自己的登录逻辑。我希望你明白我想说的是什么。谢谢。