Guest User

Sawyerrken (sawyerrken.net)

a guest
Oct 20th, 2010
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 KB | None | 0 0
  1. Login with activation email.
  2.  
  3. Assuming you have collected the user's email address in part of the email
  4.  
  5. <?php
  6. //get email address and username from form submittion
  7. $email = $_POST['email'];
  8. $username = $_POST['username'];
  9.  
  10. //create a random number for password.
  11.  
  12. function genRandomString() {
  13.     $length = 10;
  14.     $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
  15.     $string = "";  
  16.  
  17.     for ($p = 0; $p < $length; $p++) {
  18.         $string .= $characters[mt_rand(0, strlen($characters))];
  19.     }
  20.  
  21.     return $string;
  22. }
  23.  
  24. $password = genRandomString();
  25.  
  26. //encrypt password, you can choose any algorithm you want I am choosing md5
  27. $db_password = md5($password);
  28.  
  29. //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.
  30. $member_key = genRandomString();
  31.  
  32. //you should already have a table in your database to store users info and you should already have initialised your database connection
  33. //insert this new user into the dtabase
  34.  
  35. if(@mysql_query("insert into members (username, password) values('$username', '$db_password')")){
  36.     //send a mail with the password to the user
  37.  
  38.    $subject = "Your Member Registration details";
  39.  
  40. $message = "Hello Dear Whatever \n"
  41. ."Your password is $password \n"
  42. ."Regards, \n"
  43. ."jfjfjfjfj.com";
  44.  
  45.    $header = "From: $email_to\n"
  46.   . "Reply-To: $email_to\n";
  47.  
  48. @mail($email, $subject ,$message ,$header );
  49. }
  50. ?>
  51.  
  52.  
  53. //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
  54.  
  55. when the user asks to reset password,
  56. generate a random number using the genRandomString() and insert it into the members table for that user, store it as his member key.
  57. mail the member key you generated to the email for that user account.
  58.  
  59. create a form where the dude can enter his email and the key that he'll get in his email.
  60. 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.
  61. save them in the DB.
  62.  
  63. 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