开发者

Tank Auth forgot password does't work

I use CodeIgniter + Tank Auth. Only the code http://localhost/XXXXXXXX/auth/forgot_password doesn't work. The result always is: "Your activation key is incorrect or expired. Please check yo开发者_运维问答ur email again and follow the instructions."

The registration and activation are all right.


Some likely problems:

  • Cookies are not being set correctly. Check your cookie settings, and do a test to make sure you can set and read cookies. (this may be invalid if cookies are not used for the reset)
  • The reset password key is expired or wasn't set correctly. Check the database to see if hte value is correct before following the link, and check your $config['forgot_password_expire'] in Tank Auth.
  • You may be linking to the wrong URL in your email. This doesn't look right:

    http://localhost/XXXXXXXX/auth/forgot_password

    It should be something like:

    http://localhost/auth/forgot_password/XXXXXXXX

Not to discourage you from using Tank Auth, but having used it I can recommend trying Ion_Auth if you are still in the early stages. I believe it's used in PyroCMS as well if that adds any credit.


If the XXXXXXXX in your URL is indicating that you have an extra URI segment before /auth/, you should change this:

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

to this:

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

Note the different numbers in $this->uri->segment(). With an extra segment before /auth/, your user id and activation code will be passed as parameters in the 4th and 5th segment (rather than the 3rd and 4th that Tank Auth assumes).


it could be the time stamp in your database in user model function "can_reset_password" uses a UNIX_TIMESTAMP(new_password_requested)

you could echo $user_id and $new_pass_key if they are correct then the problem is with time comparison. to fix the the url to always get the last two segments

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

for the time stamp try this for the function reset_password in users model

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;
}


In the main index.php, you have to define a time zone. Example:

date_default_timezone_set('Europe/Paris');

this will ensure that the following check has all the dates with the same time zone

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜