Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Login with activation email.
- Assuming you have collected the user's email address in part of the email
- <?php
- //get email address and username from form submittion
- $email = $_POST['email'];
- $username = $_POST['username'];
- //create a random number for password.
- function genRandomString() {
- $length = 10;
- $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
- $string = "";
- for ($p = 0; $p < $length; $p++) {
- $string .= $characters[mt_rand(0, strlen($characters))];
- }
- return $string;
- }
- $password = genRandomString();
- //encrypt password, you can choose any algorithm you want I am choosing md5
- $db_password = md5($password);
- //create a member key to store in the database. The member key is what you'd send to the user when he wants to reset his password. The key changes on each use.
- $member_key = genRandomString();
- //you should already have a table in your database to store users info and you should already have initialised your database connection
- //insert this new user into the dtabase
- if(@mysql_query("insert into members (username, password) values('$username', '$db_password')")){
- //send a mail with the password to the user
- $subject = "Your Member Registration details";
- $message = "Hello Dear Whatever \n"
- ."Your password is $password \n"
- ."Regards, \n"
- ."jfjfjfjfj.com";
- $header = "From: $email_to\n"
- . "Reply-To: $email_to\n";
- @mail($email, $subject ,$message ,$header );
- }
- ?>
- //for the forgot passwor thingy, i am running late for a meeting i got by 6pm. Cant write the codes but here's the drill
- when the user asks to reset password,
- generate a random number using the genRandomString() and insert it into the members table for that user, store it as his member key.
- mail the member key you generated to the email for that user account.
- create a form where the dude can enter his email and the key that he'll get in his email.
- if the member key he enters for his account rhymes with what you have on DB, present him with a form to enter new password and confirm password.
- save them in the DB.
- Thts all. woulda loved to write this out for u but i am late for my date, sorry meeting.
Advertisement
Add Comment
Please, Sign In to add comment