Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. <?php
  2. /*
  3. Very important! You need to run SQL update!
  4. ALTER TABLE `account` ADD `reset_password` VARCHAR( 50 ) NOT NULL;
  5. */
  6. /*Config*/
  7. $realmd = array(
  8. 'db_host'=> 'localhost', //ip of db realm
  9. 'db_username' => 'mangos',//realm user
  10. 'db_password' => '',//realm password
  11. 'db_name'=> 'realmd',//realm db name
  12. );
  13. $config = array(
  14. 'path_to_thisfile' => 'http://mysite.com/lol/ownage/wow/pass_recovery.php', // Example: http://mysite.com/lol/ownage/wow/
  15. 'email_from' => 'mysite@wow.com', // Who should the email be sent from ?
  16. 'email_subject' => 'Password recovery for our site!', // Subject of the mail ??
  17. );
  18.  
  19.  
  20.  
  21. function sha_password($user,$pass){
  22. $user = strtoupper($user);
  23. $pass = strtoupper($pass);
  24.  
  25. return SHA1($user.':'.$pass);
  26. }
  27. function random_string($counts){
  28. $str = "abcdefghijklmnopqrstuvwxyz";//Count 0-25
  29. for($i=0;$i<$counts;$i++){
  30. if ($o == 1){
  31. $output .= rand(0,9);
  32. $o = 0;
  33. }else{
  34. $o++;
  35. $output .= $str[rand(0,25)];
  36. }
  37.  
  38. }
  39. return $output;
  40. }
  41.  
  42.  
  43. $realmd_bc_new_connect = mysql_connect($realmd[db_host],$realmd[db_username],$realmd[db_password]);
  44. $selectdb = mysql_select_db($realmd[db_name],$realmd_bc_new_connect);
  45.  
  46. if ($_GET[h] && $_GET[h] != '' && $_GET[h] != '0'){
  47. $output_random_pass = random_string(10);
  48. $query = mysql_query("SELECT username FROM `account` WHERE reset_password='$_GET[h]'");
  49. $res = mysql_fetch_array($query);
  50. if (mysql_num_rows($query) == 1){
  51. echo "Hi $res[username], Your password is: $output_random_pass. Please change your password fast as possible.";
  52. $pass_hash = sha_password($res[username],$output_random_pass);
  53. mysql_query("UPDATE `account` SET sha_pass_hash='$pass_hash' WHERE reset_password='$_GET[h]'");
  54. mysql_query("UPDATE `account` SET reset_password='' WHERE username='$res[username]'");
  55. }else{
  56. echo "Error.";
  57. }
  58.  
  59. }else{
  60. ?>
  61.  
  62. <?php
  63. //this is where user fill in and send by email
  64. if ($_POST[password_takeback]){
  65. $check_security = mysql_query("SELECT id FROM `account` WHERE username='$_POST[username]' AND email='$_POST[email]'");
  66. if (isset($_POST['username']) && isset($_POST['email']) && mysql_num_rows($check_security) == 1){
  67. $rand = random_string(40);
  68. mysql_query("UPDATE `account` SET reset_password='$rand' WHERE username='$_POST[username]'");
  69. $to = $_POST["email"];
  70. $from = "From: $config[email_from]";
  71. $subject = $config[email_subject];
  72. $message= "Hi $_POST[username], you have submitted a password recovery on our site. IF YOU DIDNT SUBMIT A PASSWORD REQUEST JUST DELETE THIS MAIL!. Please follow this link to complete the operation: $config[path_to_thisfile]?h=$rand";
  73. mail($to, $subject, $message, $from); // This work if you have configured your php.ini file to send email, !on linux its default.
  74. echo "An Email has been sent to you, please follow the email to complete the process.";
  75. }else{
  76. echo "Incorrect details, Please be sure that you submitted right Email and Username to your account";
  77. }
  78. }else{
  79. ?>
  80. <form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">
  81. Your Email: <input type="text" name="email">
  82.  
  83. Your Username: <input type="text" name="username">
  84.  
  85. <input type="submit" name="password_takeback">
  86. </form>
  87. <?php
  88. }
  89. }// End GET
  90. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement