2012-01-07 159 views
0

我是很新的驗證模塊,我試圖讓登錄工作,閱讀文檔和谷歌上搜索想瘋了,我有這個簡單的代碼後...Kohana的身份驗證登錄失敗每次

Auth::instance()->login('test', 'test'); 
if (Auth::instance()->logged_in()){ 
    $this->request->redirect('user/index/'); 
}else{ 
    echo 'fail'; 
} 

這始終返回false,我的註冊腳本是這樣的:

$model = ORM::factory('user'); 
$model->values(array(
     'username' => 'admin', 
     'email' => '[email protected]', 
     'password' => 'test', 
     'password_confirm' => 'test', 
    )); 
$model->save(); 

它創建用戶蠻好的,也將其設置role_id爲1和2,這意味着我已經管理員/登錄權限,但它一直沒有反正,如果我使用Auth::instance()->force_login($user);一切工作都很好,所以我猜測p可能與哈希有關,但我不知道在哪裏。

+1

是'驗證::實例() - >登錄( '管理', '測試');'? – biakaveron 2012-01-08 10:21:19

回答

2

您必須設置在config/auth.php

+0

已經不是問題了,反正現在我通過刪除 'if(isset($ this - > _ users [$ username])AND $ this - > _ users [$ username] === $ password)來解決問題'來自'\ modules \ auth \ classes \ kohana \ auth' – Linas 2012-01-07 20:26:03

0

司機「ORM」你存儲明文密碼或哈希密碼?我認爲Auth模塊登錄函數散列密碼。所以也許你應該保存哈希密碼。

您可以通過使用散列密碼:

Auth::instance()->hash('your_password');