2017-03-16 375 views
0

我嘗試創建自定義登錄頁面,但我得到一個錯誤laravel 5.2自定義登錄

Undefined index: password

我控制器代碼

$this->validate($Request, [ 
     'Email' => 'required', 
     'password' => 'required', 
     ]); 
     $email = $Request['Email']; 
     $password  = md5($Request['password']); 
     $login = new login(); 
     $login = login::where('Email', $email); 
     if(empty($password)) 
     { 
      return('404'); 
     } 
     if(Auth::attempt(['Email' => $Request->input('Email'), 'Password' =>$password])) 
     { 
      return ('ok'); 
     } 
     return ('no'); 

任何一個可以幫助我來創建自定義登錄

這是我的新代碼

但我再次GOR未定義::密碼時應

public function logincheck(Request $request) 
    { 
     $this->validate($request, [ 
     'Email' => 'required', 
     'password' => 'required', 
     ]); 
     $email = $request->Email; 
     $password  = md5($request->get('password')); 
     if(Auth::attempt(['Email' => $request->get('Email'), 'Password' =>md5($request->get('password'))])) 
     { 
      return ('ok'); 
     } 
     return ('no'); 
    } 
+0

顯示你的表格。您的輸入字段的名稱應完全匹配。這是區分大小寫的。 – Christophvh

回答

1

你的錯誤來自

$Request['password'] 

你對待請求作爲數組。這是一個對象。你做

public funciton login(Request $request) 
{ 
    $password = $request->password; 
    //or use the global helper 
    $password = request('password'); 


    //Attempt login 
    if(Auth::attempt(['Email' => $request->get('Email'), 'Password' =>$password])) 
    { 
     return ('ok'); 
    } 
} 

此外,如果你遵循Laravel教程得當,你不需要md5哈希密碼。 Auth::attemp()會爲你散列它

+0

再次我得到了同樣的錯誤 – Saran

+0

請更新您的代碼,我想看看錯誤來自哪裏。 – EddyTheDove

+0

公共函數logincheck(請求$請求) { \t $這 - >驗證($請求,[ '所需' '電子郵件'=>, '需要' '密碼'=>, \t]); \t $ email = $ request-> Email; \t $ password = md5($ request-> get('password')); \t if(Auth :: attempt(['Email'=> $ request-> get('Email'),'Password'=> md5($ request-> get('password'))])) \t { \t \t return('ok'); \t} \t return('no'); } – Saran