我在 Kohana v 2.3.4 中使用 Auth 模块。
在验证用户方面,有一个两步过程。入口点是函数登录。它的第一个任务是检索存储在数据库中的密码并检索密码并确定盐值。盐应该由一组值确定,每个值对应于 $salt.$password 散列值中的一个点,以引入盐的另一部分。就我而言,我使用的是 md5。
问题:
我找不到此 SALT 值的配置。它似乎依赖于存储在数据库中的密码中已经存在的密码。是否有一个或者我需要配置 AUTH 来这样做,因为这个登录需要是可移植的和可重现的?如果它无法检测到盐,在 hash_password 例程中,它默认使用 uniqid(),我不认为它是可移植的。
在添加用户方面,修改Auth库添加这个功能有意义吗?即,介绍我自己的自定义 SALT,我可以说,对其进行 MD5 哈希,然后使用盐生成的 md5 在 md5sum 中的给定点播种密码?
我不是安全专家,但这是否矫枉过正?当然,它可以防止要访问 md5 密码列表的人使用 md5 查找预先确定的哈希值。
如果您使用过 Kohana PHP 框架,如果您在使用它后有任何经验教训或经验可以帮助您了解解决此问题的正确方法,请告诉我。我正在阅读许多关于它的论坛和维基,但我还没有看到真正的具体意见。我本质上是在尝试获得一种可重现的方法来验证该站点中的某人,既使用 PHP,也最终使用移动设备,如 iPhone。我还在考虑最终添加对 google 朋友连接的支持,以实现 openID 支持和集成。
以下是 Kohana 中关于感兴趣功能的 Auth 模块的片段。他们有一些调试,因为我试图更好地理解发生了什么。
public function login($username, $password, $remember = FALSE)
{
if (empty($password))
return FALSE;
if (is_string($password))
{
// Get the salt from the stored password
$salt = $this->find_salt($this->driver->password($username));
Kohana::log('debug', "--- Auth_Core login salt = $salt ");
Kohana::log('debug', "--- Auth_Core login pass = $password ");
// Create a hashed password using the salt from the stored password
$password = $this->hash_password($password, $salt);
}
Kohana::log('debug', "--- Auth_Core login pass_hash = $password ");
return $this->driver->login($username, $password, $remember);
}
public function find_salt($password)
{
$salt = '';
foreach ($this->config['salt_pattern'] as $i => $offset)
{
// Find salt characters, take a good long look...
//$salt .= $password[$offset + $i];
$salt .= substr($password, $offset + $i, 0);
}
return $salt;
}
public function hash_password($password, $salt = FALSE)
{
Kohana::log('debug', "--- Auth_Core Original Pass = $password ");
if ($salt === FALSE)
{
// Create a salt seed, same length as the number of offsets in the pattern
$salt = substr($this->hash(uniqid(NULL, TRUE)), 0, count($this->config['salt_pattern']));
Kohana::log('debug', "--- Auth_Core salt created = $salt ");
}
// Password hash that the salt will be inserted into
$hash = $this->hash($salt.$password);
// Change salt to an array
$salt = str_split($salt, 1);
// Returned password
$password = '';
// Used to calculate the length of splits
$last_offset = 0;
foreach ($this->config['salt_pattern'] as $offset)
{
// Split a new part of the hash off
$part = substr($hash, 0, $offset - $last_offset);
// Cut the current part out of the hash
$hash = substr($hash, $offset - $last_offset);
// Add the part to the password, appending the salt character
$password .= $part.array_shift($salt);
// Set the last offset to the current offset
$last_offset = $offset;
}
Kohana::log('debug', "--- Auth_Core hashpw = $password + $hash ");
// Return the password, with the remaining hash appended
return $password.$hash;
}