Kohana:使用Auth模块了解和复制Salt和Hashed密码

Gar*_*ary 5 php security authentication login kohana

我在Kohana v 2.3.4中使用了Auth模块.

在验证用户方面,有两个步骤.入口点是函数登录.它的第一个任务是检索存储在数据库中的密码并检索密码并确定盐值.盐应该由一系列值确定,每个值对应于$ salt中的一个点.$ password散列值以引入另一部分盐.就我而言,我正在使用md5.

问题:

  1. 我找不到此SALT值的配置.它似乎依赖于存储在数据库中的密码中已存在的密码.是否有一个或我需要配置AUTH这样做,因为此登录需要是可移植的和可重现的?如果它无法检测到盐,则在hash_password例程中,它默认使用uniqid(),我认为它根本不可移植.

  2. 在添加用户方面,修改Auth库以添加此功能是否有意义?即,引入我自己定制的SALT,我可以说,对其进行MD5哈希,然后使用盐生成的md5在md5sum中的给定点播种密码?

  3. 我不是安全专家,但这有点过分吗?当然,它可以阻止访问md5密码列表的人使用预定哈希值的md5查找.

  4. 如果您已经使用了Kohana PHP框架,如果您在使用它之后获得了任何经验教训或经验,可能会对此问题的正确方法有所了解,请告诉我们.我正在阅读很多关于它的论坛和维基,而且我还没有看到真正的具体意见.我本质上是试图获得一种可重现的方法来验证这个站点中的某个人,无论是使用PHP还是最终来自移动设备,如iPhone.我也在考虑最终为google friend connect添加对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;
}
Run Code Online (Sandbox Code Playgroud)

Luk*_*man 3

问题1.盐配置存储在config/auth.php. 在 中找到该文件modules/auth/config,然后在您的app/config文件夹中找到该文件(您可能已经知道,Kohana 使用级联文件系统机制)。默认文件,鼓励您自定义app/config/文件夹中,如下所示:

\n\n
\n
<?php defined(\'SYSPATH\') OR die(\'No direct access allowed.\');\n\nreturn array\n(\n  \'driver\' => \'ORM\',\n  \'hash_method\' => \'sha1\',\n  \'salt_pattern\' => \'1, 3, 5, 9, 14, 15, 20, 21, 28, 30\',\n  \'lifetime\' => 1209600,\n  \'session_key\' => \'auth_user\',\n  \'users\' => array\n  (\n      // \'admin\' => \'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02\',\n  ),\n);\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

问题 2.在我看来,Auth 使用的密码哈希机制(即带有盐插入的 SHA1)是相当安全的,只要您保留您的盐,即您的盐。auth.php文件)的安全。

\n\n

问题3.Auth内置的哈希机制使用SHA1,它比MD5相对更防破解,所以我想说不要使用MD5方式,无论你的方案看起来多么复杂。安全专家 Thomas Ptacek 在他的博客中中写道:

\n\n
\n

不完全是。使用别人\xe2\x80\x99s\n密码系统。不要\xe2\x80\x99 构建你自己的。

\n\n

业界大多数\xe2\x80\x99 最严重的安全问题(例如众所周知的糟糕的 LANMAN\n 哈希)的发生是因为聪明的\n 开发人员\n 处理安全代码的方式与他们处理其余代码的方式相同。

\n
\n\n

问题4。是的,我正在使用 Kohana 构建我的小公司网站和我们的一些客户的网站,到目前为止,我没有发现 Auth 模块有任何问题,尽管我不能说太多,因为我还没有真正将其用于真正关注安全的网站。但总的来说,我认为 Kohana 是一个优秀的框架,特别是在级联文件系统机制方面。

\n