Thinkphp3.2 registration activation account password retrieval implementation

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to learn thinkphp3.2 registration and activation account password retrieval implementation.
The following describes how to activate the account and password retrieval:
Activate an account. I will give an activation code when registering it like this.
$ Jhm = $ reg-> jhm = time (). $ reg-> email;
$ Url = "http: // $ host/Member/regjhm/jhm /". base64_encode ($ jhm); // concatenate $ url; Save the activation code to the database and send the activation address to the member's email address when sending the email:



Members click this link to activate the service.

Send the url to the member's email address with the same password.



The following shows the key code:
Public function register () {// Member registration
If (IS_POST ){
$ Reg = M ('member ');
If ($ reg-> create ()){

$ Reg-> create_time = time ();
$ Host = $ _ SERVER ['HTTP _ host']; // URL
$ Jhm = $ reg-> jhm = time (). $ reg-> email;
$ Url = "http: // $ host/Member/regjhm/jhm/". base64_encode ($ jhm); // splice $ url;
If (sendMail ($ reg-> email, $ reg-> name, $ reg-> pwd, $ url )){
$ Reg-> pwd = md5 ($ reg-> pwd); // encrypted and stored in the database
$ Data = $ reg-> add ();
} Else {
$ This-> error ('email sending failed! ');
}
If ($ data! = False ){
Echo 1;
} Else {
Echo 0;
}
} Else {
$ This-> error ($ res-> getError ());
}
} Else {
$ This-> display ();
}

}

Activation:
Public function regjhm ($ jhm) {// If the activation code is consistent, the system prompts that the activation is successful. Now, the activation code does not use clearing the database activation code field.
// Base64_decode ($ jhm );
$ Member = M ('member ');
$ Jhm = base64_decode ($ jhm); // decrypt
$ Data = $ member-> where ()-> getField ('jhm '); // comparison

If ($ data ){
$ Res = $ member-> where (array ('jhm '=> $ jhm)-> setField ('jhm ',''); // clear it here. It is helpful when you log on. If the activation code does not exist, it indicates that the activation code exists, indicating that the logon is not activated.
If ($ res ){
$ This-> success ('account activated successfully! ', U ('Member/login '));
} Else {
$ This-> error ('account activation failed! ');
}

} Else {
$ This-> error ('account activated! ', U ('Member/login '));
}
}

Password Reset:
Public function resetpwd ($ email ){

$ Member = M ('member ');
$ Pwd = md5 (I ('pwd '));
If (IS_POST ){
$ Data = $ member-> where (array ('email '=> $ email)-> setField ('pwd', $ pwd); // update the password
If ($ data! = False ){
Echo 1;
} Else {
Echo 0;
}
} Else {
// Print_r ($ email );
// Exit;
$ Email = base64_decode ($ email );
$ This-> email = $ email;
$ This-> display ();
}
}



AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.