php - php codeigniter中的重置密码功能

标签 php codeigniter

我正在尝试在 codeigniter php 中编写重置密码功能,注意不要点击从哪里开始,最好的方法是什么,请帮忙

my db as like this
CREATE TABLE `members` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `username` varchar(255) NOT NULL,
 `email` varchar(255) NOT NULL,
 `password` varchar(255) NOT NULL,
 `verifystring` varchar(15) NOT NULL,
 `lostkey` varchar(100) NOT NULL,
 `active` enum('0','1') NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1

功能是这样的

//忘记密码

 public function forget_password(){

    $this->form_validation->set_rules('email','Email Address','xss_clean|required|valid_email|callback_reset_password');
    if($this->form_validation->run() == FALSE){
    $this->load->view('account/forget_password');
    }else{

        //send an email
        $this->load->library('email');
        $this->email->set_newline("\r\n");

            $this->email->from('me@gmail.com', 'Raju');
            $this->email->to('me@gmail.com');
            $this->email->subject('Email my');
            $key = 12334455;
            $message = "Please click this url to change your password ". base_url()."reset_now/".$key ;
            $message .="<br/>Thank you very much";
            $this->email->message($message);

        if($this->email->send())
                {
                    echo 'Please check your email to reset password.';
                }

                else
                {
                    show_error($this->email->print_debugger());
                }
    }

}


//email check for forget password
function reset_password($email){
    $query = $this->db->get_where('members', array('email'=>$email));

    if(!$query->num_rows()>0){
        $this->form_validation->set_message('forget_email_check', 'The %s does not exists in our database');
        return FALSE;
    }else{

        //check database fields
        /*
        $this->db->where('email', $email);
        $this->db->limit(1);
        $Q = $this->db->get('members');
        if($Q->num_rows()>0){
            $data = $Q->result_array();

            echo $data[0]['username'].'<br/>';
            echo $data[0]['password'].'<br/>';
        }

    */

        echo '<br/>'. $email.'<br/>';
    }

    //$query->free_result();
    //return true;
}

最佳答案

很简单。首先要求用户输入他们的用户名或 ID 或电子邮件或任何他们的登录凭据。 (当然不是密码)。现在有了这个值,查询数据库,如果该值存在,就检索相应的电子邮件地址。 (如果登录凭据是电子邮件,则只需检查数据库中是否存在该电子邮件地址)。然后,

  1. 创建一个随机字符串
  2. 从数据库中检索用户的电子邮件并将这个新创建的字符串发送到用户的电子邮件 ID。
  3. 更新数据库中用户的当前密码。
  4. 现在,设置一个标志,当用户使用自动生成的密码登录时,基本上会提示用户创建新密码。
  5. 一旦用户创建了新密码,然后更新数据库中的密码并更新标志。

从现在开始,无论何时用户登录,您的应用程序都不会提示用户重置用户密码。

关于php - php codeigniter中的重置密码功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7579124/

相关文章:

javascript - Array of arrays - 为什么我的数组比我认为的多了一层?

php - 是否可以在 codeigniter 中仅使用一个查询来计算特定的 id 并从另一个表中减去?

PHP 列出不存在的文件

php - Laravel - 将文件上传到数据库

php - 如何关闭这些 PHP 警告?

php - 在 sql 比较查询之前将长字符串转换为短哈希 - 提高性能?

php - 是否可以在 CodeIgniter 中对 View 进行单元测试?

php - 在 Codeigniter 中将多行插入数据库

php - 基于其他查询形成查询?

codeigniter - 将函数的变量传递给 codeigniter Controller 中的其他函数?