我正在尝试在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;
}
答案 0 :(得分:5)
这很简单。首先要求用户输入他们的用户名或ID或电子邮件或其登录凭据。 (当然不是密码)。现在使用该值,查询数据库,如果值存在,只需检索相应的电子邮件地址。 (如果登录凭据是电子邮件,则只需检查数据库中是否存在电子邮件地址)。然后,
从现在开始,只要用户登录,您的应用程序就不会提示用户重置用户密码。