3
我已經嘗試了以下代碼在Laravel 5.2中進行身份驗證。但我不知道如何使登錄成爲現實。我在if語句後嘗試Auth::login(true)
,但無法正常工作。我找到了一些關於這個話題的文章,但我找不到一個詳細的例子。如何在Laravel 5.2中無數據庫進行身份驗證?
public static function Login($email,$password)
{
$fp = fsockopen ("www.mydomain.com" , 110);
if (!$fp) {
return "Connection Error";
}
$trash = fgets ($fp, 128);
fwrite ($fp, "USER ".$email."\r\n");
$trash = fgets ($fp, 128);
fwrite ($fp, "PASS ".$password."\r\n");
$result = fgets ($fp, 128);
if(substr ($result, 0, 3) == '+OK')
return true; //user will be logged in and then redirect
else
return false;
}
如果可能的話,你可以在這裏添加一個代碼,如何使auth真正嗎?
P.S.我可以在登錄後用簡單的查詢使用電子郵件檢索用戶信息。
這是一個很酷的問題。您需要創建自己的[身份驗證提供程序](https://laravel.com/docs/5.2/authentication#adding-custom-user-providers),然後將該帖子中提供的邏輯用於此提供程序。 – manix
我想我需要一個詳細的代碼示例。我一遍又一遍地閱讀,但我無法實現它:( – drxy
我認爲你可以使用Laravel的** HTTP基本驗證** https://laravel.com/docs/master/authentication#http-basic-authentication –