是否可以在沒有用戶模型的情況下使用身份驗證組件?我想只有一個用戶在我的應用程序,所以我不想讓用戶模型,我只想登錄一個登錄名/密碼將被存儲在PHP文件。CakePHP身份驗證組件授權,無需用戶模型
1
A
回答
6
簡單的答案是否。
較長的答案是您要使用該模型來存儲此信息。在我看來,將用戶密碼存儲在PHP文件中是一個非常糟糕的主意。你會設置你的系統是完全不靈活的。當你有5個用戶時會發生什麼?
如果有一個users
數據庫表設置,然後一個users
PHP文件將會好得多。自從Cake的AuthComponent
設置爲處理數據庫表後,從長遠來看,這將會減少很多工作。另外,read this post on Stack Overflow about storing passwords。它將提供一些有關爲什麼蛋糕的AuthComponent
它的工作方式的見解。
0
雖然你可以創建一個自定義認證類,但除了學習內部行爲之外,我不知道如何使用它。
// Controller/Component/Auth/CustomBasicAuthenticate.php
class CustomBasicAuthenticate {
public function authenticate(CakeRequest $request, CakeResponse $response) {
return true;
}
public function getUser($request) {
if (env('PHP_AUTH_USER') === 'foo' && env('PHP_AUTH_PW') === 'bar') {
return array(
'User' => array(
'id' => '1', 'username' => 'foo', 'password' => 'bar'
)
);
} else {
return false;
}
}
public function unauthenticated(CakeRequest $request, CakeResponse $response) {
$response->statusCode('401');
$response->header('WWW-Authenticate: Basic realm="My Realm"');
$response->body('fail');
$response->send();
}
}
// Controller/HelloController.php
class HelloController extends AppController {
public $autoRender = false;
public $uses = array('User');
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'hello',
'action' => 'index',
),
'authenticate' => array(
'CustomBasic' => array('userModel' => 'User')
)
)
);
public function index() {
echo 'ok';
}
}
相關問題
- 1. Asp.net用戶身份驗證和授權
- 2. CakePHP的認證授權,而無需用戶模型
- 3. 身份驗證和授權
- 4. Couchdb身份驗證/授權
- 5. 身份驗證和授權
- 6. cakephp用戶身份驗證
- 7. Windows身份驗證當前用戶模擬401未授權
- 8. CakePHP的幫助 - 簡單的身份驗證和授權應用
- 9. 創建安全身份驗證/授權模型
- 10. Cakephp身份驗證組件故障
- 11. JSP - 身份驗證和授權
- 12. RavenDB IIS身份驗證/授權
- 13. JSF身份驗證和授權
- 14. WEB API 2身份驗證和授權
- 15. RavenDB身份驗證和授權
- 16. ASP.Net身份驗證和授權選項
- 17. Spring Security的授權和身份驗證
- 18. ASP.Net/MVC授權Vs的身份驗證
- 19. Angularjs和WebAPI - 身份驗證和授權
- 20. Reactivemongo的身份驗證和授權
- 21. Tweepy身份驗證與授權
- 22. Restful身份驗證和授權
- 23. 身份驗證v/s授權
- 24. 身份驗證和授權,djangorestframework
- 25. 身份驗證和授權系統
- 26. C#SMF身份驗證(授權)
- 27. ASP.NET Web API授權和身份驗證
- 28. 身份驗證和授權 - 新安全
- 29. Net Sql AZMan身份驗證和授權
- 30. 自定義身份驗證未授權