Advertisement
Guest User

Untitled

a guest
Aug 5th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. <?php
  2. require_once 'DB_Functions1.php';
  3. $db = new DB_Functions1();
  4.  
  5. $forgotpassword = $_POST['email'];
  6. $randomcode = $db->random_string();
  7.  
  8. $subject = "Password Recovery";
  9. $message = "Hello User,nnYour Password is sucessfully changed. Your new Password is $randomcode . Login with your new Password and change it in the User Panel.";
  10. $from = "contact@learn2crack.com";
  11. $headers = "From:" . $from;
  12. if ($db->isUserExisted($forgotpassword)) {
  13.  
  14. //$user = $db->forgotPassword($forgotpassword, $encrypted_password, $salt);
  15. $user = $db->forgotPassword($forgotpassword, $randomcode);
  16. if ($user) {
  17. $response["success"] = 1;
  18. mail($forgotpassword,$subject,$message,$headers);
  19. // $to = $forgotpassword;
  20. // $subject = "Password Recovery";
  21. // $message = "Hello User,nnYour Password is sucessfully changed. Your new Password is $randomcode . Login with your new Password and change it in the User Panel.";
  22.  
  23. echo json_encode($response);
  24. }
  25. else {
  26. $response["error"] = 1;
  27. echo json_encode($response);
  28. }
  29. }else{
  30. $response["error"] = "fail";
  31. echo json_encode($response);
  32. }
  33. mysql_close($conn);
  34.  
  35. ?>
  36.  
  37. <?php
  38.  
  39.  
  40. class DB_Functions1{
  41.  
  42. public function random_string()
  43. {
  44. $character_set_array = array();
  45. $character_set_array[] = array('count' => 7, 'characters' => 'abcdefghijklmnopqrstuvwxyz');
  46. $character_set_array[] = array('count' => 1, 'characters' => '0123456789');
  47. $temp_array = array();
  48. foreach ($character_set_array as $character_set) {
  49. for ($i = 0; $i < $character_set['count']; $i++) {
  50. $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];
  51. }
  52. }
  53. shuffle($temp_array);
  54. return implode('', $temp_array);
  55. }
  56.  
  57.  
  58. public function forgotPassword($forgotpassword, $randomcode){//$newpassword
  59. $result = mysql_query("UPDATE users SET password_app = '$randomcode' WHERE email = '$forgotpassword'");
  60.  
  61.  
  62. if ($result) {
  63.  
  64. return true;
  65.  
  66. }
  67. else
  68. {
  69. return false;
  70. }
  71.  
  72. }
  73.  
  74. public function isUserExisted($email) {
  75. $result = mysql_query("SELECT email from users WHERE email = '$email'");
  76. $no_of_rows = mysql_num_rows($result);
  77. if ($no_of_rows > 0) {
  78. // user existed
  79. return true;
  80. } else {
  81. // user not existed
  82. return false;
  83. }
  84. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement