忘记密码在codeigniter [英] Forgot password in codeigniter

查看:260
本文介绍了忘记密码在codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为登录页面实施忘记的密码。首先验证电子邮件,然后生成一个字符串,然后发送一个链接与密钥和电子邮件到特定的邮件。

I need to implement a forgot password to a login page.First i verify email then generate a string afterthat send a link with key and email to the particular mail.

我知道如何重置,但是什么happend收到该邮件的链接

I know how to reset but what happend receive the link to that mail

$message= "<a href='".base_url()."user/reset_pass/$key/$email'>";

这是我提供的链接

请给一个suggetion

please give a suggetion

推荐答案

首先,您需要检查当用户点击忘记密码时是否存在会话。
如果否,则为您将从用户处获取的电子邮件设置验证方法。

First you need to check if session exist when user click on forgot password. if No,then set validation method for email which you will be taking from user.

如下:

$this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_email_exists');

email_exists 方法中,检查用户是否存在或不使用给定的电子邮件ID。

In email_exists method,check if user exists or not with the given email id.

如果用户存在,则创建邮件函数。在发送重置密码的链接中。

if user exists then create a mail function.In message send link for resetting password.

$slug = md5($user->user_id . $user->email . date('Ymd'));
    $this->email->message('To reset your password please click the link below and follow the instructions:

'. site_url('forgotpassword/reset/'.$user->user_id .'/'. $slug) .'
If you did not request to reset your password then please just ignore this email and no changes will occur.
Note: This reset code will expire after '. date('j M Y') .'.');

并发送邮件。

用户点击重置链接点,该方法将再次检查session.if会话存在重定向使用到首页,否则从URL获得第三和第四段。

when user click on reset link which point the method will again check session.if session exists redirect use to Homepage else get third and fourth segment from url.

$user_id = $this->uri->segment(3);
if(!$user_id) show_error('Invalid reset code.');
$hash = $this->uri->segment(4);
if(!$hash) show_error('Invalid reset code.');

从url.again中取用户ID make $ slug 从db值,并与url $ slug .if进行比较,然后为用户提供重置字段的密码和确认密码。

Taking user id from url.again make $slug from db values and compare it with url $slug.if both matched then provide user the reset fields with password and confirm password.

如果两者都匹配,请更新密码。

If both password match.Update the password.

这篇关于忘记密码在codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆