[英]Laravel 5.7 Auth Problem can't get access
即使一切正常,我也無法訪問我的登錄身份驗證,直到我進行遷移刷新以從0開始測試一切是否正常為止。 我創建了一個用戶,但是當我嘗試登錄時,僅顯示錯誤,好像我的數據不正確。
public function login(Request $request) {
if($request->isMethod('post')){
$data = $request->input();
if (Auth::attempt(['email'=>$data['email'],'password'=>$data['password']])) {
return redirect('/admin/dashboard');
}else{
return redirect('admin/')->with ('msg_error','Pseudo ou mot de passe invalide');
}
}
return view ('admin.admin_login');
}
這是我的登錄表格
<form id="loginform" class="form-vertical" method="post" action="{{ url('admin') }} ">@csrf
<div class="control-group">
<div class="controls">
<div class="main_input_box">
<span class="add-on bg_lg"><i class="icon-user"> </i></span><input type="email" name="email" placeholder="Utulisateur" />
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<div class="main_input_box">
<span class="add-on bg_ly"><i class="icon-lock"></i></span><input type="password" name="password" placeholder="Mot de Passe" />
</div>
</div>
</div>
<div class="form-actions">
<span class="pull-left"><a href="#" class="flip-link btn btn-info" id="to-recover">Mot de passe oublié ?</a></span>
<span class="pull-right"><input type="submit" value="Se connecter" class="btn btn-success" /></span>
</div>
</form>
用戶創建文件:
$user = new User;
$user->name = $data['name'];
$user->role = $data['role'];
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->save();
來自輸入的數據:
array(3) {
["_token"]=>
string(40) "2h4nA3WuLSlWfpInCH45eUZqtyvHWEg5K7aYWC83"
["email"]=>
string(14) "test@email.com"
["password"]=>
string(6) "000000"
}
和使用哈希檢查后的數據
object(App\User)#266 (27) {
["fillable":protected]=>
array(6) {
[0]=>
string(4) "name"
[1]=>
string(5) "email"
[2]=>
string(5) "level"
[3]=>
string(8) "password"
[4]=>
string(6) "status"
[5]=>
string(15) "activation_code"
}
["hidden":protected]=>
array(2) {
[0]=>
string(8) "password"
[1]=>
string(14) "remember_token"
}
["connection":protected]=>
string(5) "mysql"
["table":protected]=>
NULL
["primaryKey":protected]=>
string(2) "id"
["keyType":protected]=>
string(3) "int"
["incrementing"]=>
bool(true)
["with":protected]=>
array(0) {
}
["withCount":protected]=>
array(0) {
}
["perPage":protected]=>
int(15)
["exists"]=>
bool(true)
["wasRecentlyCreated"]=>
bool(false)
["attributes":protected]=>
array(9) {
["id"]=>
int(1)
["name"]=>
string(5) "Test1"
["role"]=>
string(5) "Admin"
["email"]=>
string(14) "test@email.com"
["email_verified_at"]=>
string(19) "2018-10-21 00:00:00"
["password"]=>
string(60) "$2y$10$1FRa6tZz9Q.NycSVEickte/zBXfLjSlONH0Byiu363bBtQZVXLbwS"
["remember_token"]=>
NULL
["created_at"]=>
string(19) "2018-10-21 11:39:51"
["updated_at"]=>
string(19) "2018-10-21 11:39:51"
}
["original":protected]=>
array(9) {
["id"]=>
int(1)
["name"]=>
string(5) "Test1"
["role"]=>
string(5) "Admin"
["email"]=>
string(14) "test@email.com"
["email_verified_at"]=>
string(19) "2018-10-21 00:00:00"
["password"]=>
string(60) "$2y$10$1FRa6tZz9Q.NycSVEickte/zBXfLjSlONH0Byiu363bBtQZVXLbwS"
["remember_token"]=>
NULL
["created_at"]=>
string(19) "2018-10-21 11:39:51"
["updated_at"]=>
string(19) "2018-10-21 11:39:51"
}
["changes":protected]=>
array(0) {
}
["casts":protected]=>
array(0) {
}
["dates":protected]=>
array(0) {
}
["dateFormat":protected]=>
NULL
["appends":protected]=>
array(0) {
}
["dispatchesEvents":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["relations":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["timestamps"]=>
bool(true)
["visible":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["rememberTokenName":protected]=>
string(14) "remember_token"
}
bool(false)
object(App\User)#279 (27) {
["fillable":protected]=>
array(6) {
[0]=>
string(4) "name"
[1]=>
string(5) "email"
[2]=>
string(5) "level"
[3]=>
string(8) "password"
[4]=>
string(6) "status"
[5]=>
string(15) "activation_code"
}
["hidden":protected]=>
array(2) {
[0]=>
string(8) "password"
[1]=>
string(14) "remember_token"
}
["connection":protected]=>
string(5) "mysql"
["table":protected]=>
NULL
["primaryKey":protected]=>
string(2) "id"
["keyType":protected]=>
string(3) "int"
["incrementing"]=>
bool(true)
["with":protected]=>
array(0) {
}
["withCount":protected]=>
array(0) {
}
["perPage":protected]=>
int(15)
["exists"]=>
bool(true)
["wasRecentlyCreated"]=>
bool(false)
["attributes":protected]=>
array(9) {
["id"]=>
int(1)
["name"]=>
string(5) "Test1"
["role"]=>
string(5) "Admin"
["email"]=>
string(14) "test@email.com"
["email_verified_at"]=>
string(19) "2018-10-21 00:00:00"
["password"]=>
string(60) "$2y$10$1FRa6tZz9Q.NycSVEickte/zBXfLjSlONH0Byiu363bBtQZVXLbwS"
["remember_token"]=>
NULL
["created_at"]=>
string(19) "2018-10-21 11:39:51"
["updated_at"]=>
string(19) "2018-10-21 11:39:51"
}
["original":protected]=>
array(9) {
["id"]=>
int(1)
["name"]=>
string(5) "Test1"
["role"]=>
string(5) "Admin"
["email"]=>
string(14) "test@email.com"
["email_verified_at"]=>
string(19) "2018-10-21 00:00:00"
["password"]=>
string(60) "$2y$10$1FRa6tZz9Q.NycSVEickte/zBXfLjSlONH0Byiu363bBtQZVXLbwS"
["remember_token"]=>
NULL
["created_at"]=>
string(19) "2018-10-21 11:39:51"
["updated_at"]=>
string(19) "2018-10-21 11:39:51"
}
["changes":protected]=>
array(0) {
}
["casts":protected]=>
array(0) {
}
["dates":protected]=>
array(0) {
}
["dateFormat":protected]=>
NULL
["appends":protected]=>
array(0) {
}
["dispatchesEvents":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["relations":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["timestamps"]=>
bool(true)
["visible":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["rememberTokenName":protected]=>
string(14) "remember_token"
}
bool(false)
我不知道問題出在哪里
根據Hash::check('000000', $user->password);
的錯誤返回Hash::check('000000', $user->password);
,密碼不是數據庫中000000
的哈希值。
您可以使用
$user->update(['password' => bcrypt('000000')]);
Bcrypt是Hash :: make的幫助函數。 使用artisan tinker
將使此過程變得容易,因為它為您提供了一個交互式控制台來運行命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.