【问题标题】:Tank Auth forgot password does't workTank Auth忘记密码不起作用
【发布时间】:2011-05-07 10:07:13
【问题描述】:

我使用 CodeIgniter + Tank Auth。只有代码http://localhost/XXXXXXXX/auth/forgot_password 不起作用。 结果总是: “您的激活密钥不正确或已过期。请再次检查您的电子邮件并按照说明操作。”

注册激活就OK了。

【问题讨论】:

  • 没有任何代码真的很难分辨。也许令牌没有保存到数据库中。对于未来,选择拥有 > 0 个关注者的标签

标签: codeigniter tankauth


【解决方案1】:

一些可能的问题:

  • Cookie 设置不正确。检查您的 cookie 设置,并进行测试以确保您可以设置和读取 cookie。 (如果不使用 cookie 进行重置,这可能无效)
  • 重置密码密钥已过期或未正确设置。在点击链接之前检查数据库以查看 hte 值是否正确,并在 Tank Auth 中检查您的 $config['forgot_password_expire']
  • 您可能在电子邮件中链接到错误的 URL。 这看起来不对:

    http://localhost/XXXXXXXX/auth/forgot_password

    应该是这样的:

    http://localhost/auth/forgot_password/XXXXXXXX

并不是要阻止您使用 Tank Auth,但如果您仍处于早期阶段,我可以建议您尝试 Ion_Auth。我相信它也用于PyroCMS,如果这增加了任何信用的话。

【讨论】:

  • 我在将 ion_auth 配置为 hmvc 模块时遇到了一些麻烦,但 tank_auth 完美无缺。虽然,我仍然遇到同样的电子邮件问题。
【解决方案2】:

如果你的 URL 中的 XXXXXXXX 表明你在 /auth/ 之前有一个额外的 URI 段,你应该改变这个:

function reset_password()
{
    $user_id = $this->uri->segment(3);
    $new_pass_key = $this->uri->segment(4);

到这里:

function reset_password()
{
    $user_id = $this->uri->segment(4);
    $new_pass_key = $this->uri->segment(5);

注意 $this->uri->segment() 中的不同数字。在 /auth/ 之前有一个额外的段,您的用户 ID 和激活码将作为参数传递到第 4 和第 5 段(而不是 Tank Auth 假定的第 3 和第 4 段)。

【讨论】:

    【解决方案3】:

    它可能是您数据库中的时间戳 在用户模型函数“can_reset_password”中 使用 UNIX_TIMESTAMP(new_password_requested)

    如果 $user_id 和 $new_pass_key 正确,您可以回显它们,那么问题在于时间比较。 修复 url 以始终获取最后两个段

    $break =$this->uri->total_segments();
    $new_pass_key= $this->uri->segment($break);
    $user_id= $this->uri->segment($break-1);
    

    对于时间戳试试这个用户模型中的函数reset_password

    function reset_password($user_id, $new_pass, $new_pass_key, $expire_period = 900)
    {
        $this->load->helper('date');
        $this->db->set('password', $new_pass);
        $this->db->set('new_password_key', NULL);
        $this->db->set('new_password_requested', NULL);
        $this->db->where('id', $user_id);
        $this->db->where('new_password_key', $new_pass_key);
        $this->db->where('UNIX_TIMESTAMP(new_password_requested) >=',mysql_to_unix( time() - $expire_period));
    
        $this->db->update($this->table_name);
        return $this->db->affected_rows() > 0;
    }
    

    【讨论】:

      【解决方案4】:

      在主 index.php 中,您必须定义一个时区。示例:

      date_default_timezone_set('Europe/Paris');
      

      这将确保以下检查具有相同时区的所有日期

      $this->db->where('UNIX_TIMESTAMP(new_password_requested) >', time() - $expire_period);
      

      【讨论】:

        猜你喜欢
        • 2013-06-10
        • 2012-06-09
        • 2016-11-23
        • 1970-01-01
        • 1970-01-01
        • 2014-06-07
        • 2016-07-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多