Я начинаю php
и теперь застреваю при отправке нового пароля пользователю по электронной почте, если пользователь запросил в android
.
ForgetPassword.php
<?php require_once('DB_Functions.php'); $db = new DB_Functions(); $forgotpassword = $_POST['forgotpassword']; $randomcode = $db->random_string(); if(isset($_POST['forgotpassword'])){ $hash = $db->hashSSHA($randomcode); $encrypted_password = $hash["encrypted"]; // encrypted password $salt = $hash["salt"]; $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.nnRegards,nLearn2Crack Team."; $from = "contact@learn2crack.com"; $headers = "From:" . $from; if ($db->isUserExisted($forgotpassword)) { $user = $db->forgotPassword($forgotpassword, $encrypted_password, $salt); if ($user) { $response["success"] = 1; mail($forgotpassword,$subject,$message,$headers); echo json_encode($response); } else { $response["error"] = 1; echo json_encode($response); } } // user is already existed - error response } else { $response["error"] = 2; $response["error_msg"] = "User not exist"; echo json_encode($response); } ?>
при<?php require_once('DB_Functions.php'); $db = new DB_Functions(); $forgotpassword = $_POST['forgotpassword']; $randomcode = $db->random_string(); if(isset($_POST['forgotpassword'])){ $hash = $db->hashSSHA($randomcode); $encrypted_password = $hash["encrypted"]; // encrypted password $salt = $hash["salt"]; $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.nnRegards,nLearn2Crack Team."; $from = "contact@learn2crack.com"; $headers = "From:" . $from; if ($db->isUserExisted($forgotpassword)) { $user = $db->forgotPassword($forgotpassword, $encrypted_password, $salt); if ($user) { $response["success"] = 1; mail($forgotpassword,$subject,$message,$headers); echo json_encode($response); } else { $response["error"] = 1; echo json_encode($response); } } // user is already existed - error response } else { $response["error"] = 2; $response["error_msg"] = "User not exist"; echo json_encode($response); } ?>
DB_Functions.php
<?php require_once('dbConnect.php'); class DB_Functions { private $db; /** * Random string which is sent by mail to reset password */ 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 isUserExisted($email) { $result = mysqli_query($this->db,"SELECT email from users WHERE email = '$email'"); if($result) { $no_of_rows = mysqli_num_rows($result); if ($no_of_rows > 0) { // user existed return true; } }else { // user not existed return false; } } public function hashSSHA($password) { $salt = sha1(rand()); $salt = substr($salt, 0, 10); $encrypted = base64_encode(sha1($password . $salt, true) . $salt); $hash = array("salt" => $salt, "encrypted" => $encrypted); return $hash; } public function forgotPassword($forgotpassword, $newpassword, $salt){ $result = mysqli_query("UPDATE `users` SET 'password` = '$newpassword' WHERE `email` = '$forgotpassword'"); if ($result) { return true; } else { return false; } } } ?>
dbConnect.php
<?php define('HOST','127.0.0.1:3307'); define('USER','root'); define('PASS',''); define('DB','androiddb'); //Connecting to Database $con= mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect'); ?>
Это то, что я пробовал до сих пор, к сожалению, это дает мне кучу ошибок! Любая помощь будет оценена по достоинству.
Я получаю учебник отсюда .
Ошибка (последняя)
Примечание: Неопределенный индекс: забытый пароль в C: \ xampp \ htdocs \ Android \ CRUD \ forgetPassword.php в строке 4 {"error": 2, "error_msg": "Пользователь не существует"}