PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/php-scripts/forgotPassword.php

https://bitbucket.org/dedesfr/kiducation
PHP | 89 lines | 51 code | 7 blank | 31 comment | 6 complexity | 192916e29d506d6024154f59aff0a14c MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. use PHPMailer\PHPMailer\PHPMailer;
  3. use PHPMailer\PHPMailer\Exception;
  4. require '../PHPMailer/src/Exception.php';
  5. require '../PHPMailer/src/PHPMailer.php';
  6. require '../PHPMailer/src/SMTP.php';
  7. include_once "../base/koneksi.php";
  8. session_start();
  9. /*
  10. require_once __DIR__ . '/src/autoload.php';
  11. $siteKey = '6LdeVxAUAAAAAJtKL2NopanvfzhbfPYn3_NkpeUg';
  12. $secret = '6LdeVxAUAAAAADr0Lqr61rwfTPzRNSwfPMto02Mq';
  13. $lang = 'en';
  14. */
  15. $email = @$_POST['email'];
  16. //$recap = @$_POST['g-recaptcha-response'];
  17. /*
  18. if(!isset($recap) && empty($recap))
  19. {
  20. $_SESSION['error'] = "Please click on the reCAPTCHA box.";
  21. header("location:../index.php");
  22. }
  23. else*/if($email == "")
  24. {
  25. $_SESSION['error'] = "Email harus diisi";
  26. header("location:../login.php");
  27. }
  28. else
  29. {
  30. /*
  31. $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
  32. $responseData = json_decode($verifyResponse);
  33. if($responseData->success):
  34. */
  35. $loginQ = mysqli_query($con, "select * from users where email = '$email'");
  36. $login = mysqli_fetch_array($loginQ);
  37. if($login != 0){
  38. $fullname = $login['fullname'];
  39. $password = substr(md5(uniqid(rand(),1)),3,10);
  40. $pass = password_hash($password, PASSWORD_DEFAULT);
  41. $update = mysqli_query($con, "UPDATE users SET password = '$pass' WHERE email = '$email'");
  42. if ($update == 1) {
  43. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  44. try {
  45. //Server settings
  46. $mail->isSMTP(); // Set mailer to use SMTP
  47. $mail->Host = 'cpanel04.indocenter.co.id'; // Specify main and backup SMTP servers
  48. $mail->SMTPAuth = true; // Enable SMTP authentication
  49. $mail->Username = 'admin@kiducation.id'; // SMTP username
  50. $mail->Password = 'Kiducationadmin123'; // SMTP password
  51. $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
  52. $mail->Port = 465; // TCP port to connect to
  53. //Recipients
  54. $mail->setFrom('admin@kiducation.id', 'Kiducation.id');
  55. $mail->addAddress($email); // Add a recipient
  56. //Attachments
  57. // $mail->addAttachment('images/testi-1.jpg'); // Add attachments
  58. // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  59. //Content
  60. $mail->isHTML(true); // Set email format to HTML
  61. $mail->Subject = 'Forgot Password';
  62. $mail->Body = 'Hi '.$fullname.', <br> <br> You can use this ' .$password.' to login in <a href="http://kiducation.id">www.kiducation.id!</a> <br> <br> For more security issues please change the password on your own <br> <br> Sincerely, <br> <br> <img src="http://kiducation.id/images/logokidu.png" alt="kidcation logo" width="150"> <br> Fun Arts and Workshop Organizer For Kids';
  63. $mail->send();
  64. } catch (Exception $e) {
  65. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  66. }
  67. header("location:../login.php");
  68. }
  69. } else {
  70. $_SESSION['error'] = "Email belum terdaftar";
  71. header("location:../forgotPassword.php");
  72. }
  73. /*
  74. else:
  75. $_SESSION['error'] = "Robot verification failed, please try again.";
  76. header("location:../index.php");
  77. endif;
  78. */
  79. }
  80. mysqli_close($con);
  81. ?>