【问题标题】:Codeigniter, tank_auth code doesnt work after moving to the new serverCodeigniter,坦克身份验证代码在移动到新服务器后不起作用
【发布时间】:2012-03-25 23:17:52
【问题描述】:

迁移到新服务器后,我收到了很多这样的通知:

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: account/settings.php

Line Number: 28

account/settings.php查看@line 28内容为:

echo $user->description;

到处都出现错误我试图从$user 变量中获取信息。 我猜它与tank_auth 有关:我正在通过控制器传递$user 数据:

$data['user'] = $this->tank_auth->user();
[..]
$this->load->view('account/settings', $data);

...我已经登录了。

我的目录路径与早期服务器上的完全相同

问题出在哪里?

【问题讨论】:

    标签: php codeigniter tankauth


    【解决方案1】:

    这可能是因为您将服务器哈希设置为不可移植..

    application/config/tank_auth.php 中的第 13-23 行

    /*
    |--------------------------------------------------------------------------
    | Security settings
    |
    | The library uses PasswordHash library for operating with hashed passwords.
    | 'phpass_hash_portable' = Can passwords be dumped and exported to another server. If set to FALSE then you won't be able to use this database on another server.
    | 'phpass_hash_strength' = Password hash strength.
    |--------------------------------------------------------------------------
    */
    ## Set this to TRUE
    $config['phpass_hash_portable'] = FALSE;
    $config['phpass_hash_strength'] = 8;
    

    application/libraries/phpass-0.1/PasswordHash.php 的第 203-235 行

    如果你好奇这个配置在哪里发挥作用,它在河豚哈希创建中:

    function HashPassword($password)
    {
        $random = '';
    
        if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
            $random = $this->get_random_bytes(16);
            $hash =
                crypt($password, $this->gensalt_blowfish($random));
            if (strlen($hash) == 60)
                return $hash;
        }
    
        if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
            if (strlen($random) < 3)
                $random = $this->get_random_bytes(3);
            $hash =
                crypt($password, $this->gensalt_extended($random));
            if (strlen($hash) == 20)
                return $hash;
        }
    
        if (strlen($random) < 6)
            $random = $this->get_random_bytes(6);
        $hash =
            $this->crypt_private($password,
            $this->gensalt_private($random));
        if (strlen($hash) == 34)
            return $hash;
    
        # Returning '*' on error is safe here, but would _not_ be safe
        # in a crypt(3)-like function used _both_ for generating new
        # hashes and for validating passwords against existing hashes.
        return '*';
    }
    

    如果这不能解决问题

    试试print_r($user); 什么回来?

    【讨论】:

    • 但是……这是怎么回事?是比较表的创建日期还是它们的 md5 哈希?
    • 我刚刚将$config['phpass_hash_portable']设置为TRUE,并重新登录了我的帐户,但仍然无法使用。
    • 您必须完全重做用户,生成密码时使用的哈希值会考虑主机信息(IE 服务器主机名、服务器 IP 地址、mac 地址)。相信我,我有 400 多个用户,但在创建用户之前我忘记设置了。
    • 我用库中的摘录更新了我的答案,该摘录显示了此配置项的作用。
    • 啊。我不知道我必须清除帐户...它非常不安全,但我没有查看我的配置文件是我的错。我很幸运,数据库中只有 3 个帐户...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    相关资源
    最近更新 更多