2013-02-17 57 views
0

Kohana:当我使用Auth模块时,获取下面提到的错误: 必须在auth配置中设置有效的哈希键。Kohana:Kohana中的Auth哈希键问题3.2

这是被称为

代码是:

public function hash($str) 
{  
if (! $this->_config['hash_method'])   return $str;   
if (! $this->_config['hash_key'])   
throw new Kohana_Exception('A valid hash key must be set in your auth config.');   
return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']); 
} 

在这里,我可以看到,HASH_KEY不来正常,当我删除此检查一切正常。你能帮助理解这个问题吗?我使用的是Auth :: instance() - > login(“userid”,“password”);我使用的是Auth :: instance()

+1

你是否在你的配置中设置了散列键,就像它说的那样? – zombor 2013-02-17 15:37:10

+0

我们如何设置哈希键,你能指引我正确的方向吗?此外,我使用Kohana活动记录而不是ORM,因此我该如何设置用户详细信息的角色?任何可以引导的链接?提前致谢。 – 2013-02-17 18:53:47

回答

1

在你的auth配置文件中(如果你没有一个,把它放在这里./application/config/auth.php),你需要定义一个散列键。使用随机字符串。例如:

<?php defined('SYSPATH') or die('No direct access allowed.'); 

return array(

    'driver'  => 'ORM', 
    'hash_method' => 'sha256', 

    // This is the important line 
    'hash_key'  => 'seilrrskj34sljusd', 
    'lifetime'  => 1209600, 
    'session_type' => Session::$default, 
    'session_key' => 'auth_user', 

    // Username/password combinations for the Auth File driver 
    'users' => array() 

); 
+0

非常感谢,这工作。 – 2013-02-18 04:55:21