Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'DB_Functions1.php';
- $db = new DB_Functions1();
- $forgotpassword = $_POST['email'];
- $randomcode = $db->random_string();
- $subject = "Password Recovery";
- $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.";
- $from = "contact@learn2crack.com";
- $headers = "From:" . $from;
- if ($db->isUserExisted($forgotpassword)) {
- //$user = $db->forgotPassword($forgotpassword, $encrypted_password, $salt);
- $user = $db->forgotPassword($forgotpassword, $randomcode);
- if ($user) {
- $response["success"] = 1;
- mail($forgotpassword,$subject,$message,$headers);
- // $to = $forgotpassword;
- // $subject = "Password Recovery";
- // $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.";
- echo json_encode($response);
- }
- else {
- $response["error"] = 1;
- echo json_encode($response);
- }
- }else{
- $response["error"] = "fail";
- echo json_encode($response);
- }
- mysql_close($conn);
- ?>
- <?php
- class DB_Functions1{
- public function random_string()
- {
- $character_set_array = array();
- $character_set_array[] = array('count' => 7, 'characters' => 'abcdefghijklmnopqrstuvwxyz');
- $character_set_array[] = array('count' => 1, 'characters' => '0123456789');
- $temp_array = array();
- foreach ($character_set_array as $character_set) {
- for ($i = 0; $i < $character_set['count']; $i++) {
- $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];
- }
- }
- shuffle($temp_array);
- return implode('', $temp_array);
- }
- public function forgotPassword($forgotpassword, $randomcode){//$newpassword
- $result = mysql_query("UPDATE users SET password_app = '$randomcode' WHERE email = '$forgotpassword'");
- if ($result) {
- return true;
- }
- else
- {
- return false;
- }
- }
- public function isUserExisted($email) {
- $result = mysql_query("SELECT email from users WHERE email = '$email'");
- $no_of_rows = mysql_num_rows($result);
- if ($no_of_rows > 0) {
- // user existed
- return true;
- } else {
- // user not existed
- return false;
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement