/php-scripts/forgotPassword.php
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
- <?php
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- require '../PHPMailer/src/Exception.php';
- require '../PHPMailer/src/PHPMailer.php';
- require '../PHPMailer/src/SMTP.php';
- include_once "../base/koneksi.php";
- session_start();
- /*
- require_once __DIR__ . '/src/autoload.php';
- $siteKey = '6LdeVxAUAAAAAJtKL2NopanvfzhbfPYn3_NkpeUg';
- $secret = '6LdeVxAUAAAAADr0Lqr61rwfTPzRNSwfPMto02Mq';
- $lang = 'en';
- */
- $email = @$_POST['email'];
- //$recap = @$_POST['g-recaptcha-response'];
- /*
- if(!isset($recap) && empty($recap))
- {
- $_SESSION['error'] = "Please click on the reCAPTCHA box.";
- header("location:../index.php");
- }
- else*/if($email == "")
- {
- $_SESSION['error'] = "Email harus diisi";
- header("location:../login.php");
- }
- else
- {
- /*
- $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
- $responseData = json_decode($verifyResponse);
-
- if($responseData->success):
- */
- $loginQ = mysqli_query($con, "select * from users where email = '$email'");
- $login = mysqli_fetch_array($loginQ);
- if($login != 0){
- $fullname = $login['fullname'];
- $password = substr(md5(uniqid(rand(),1)),3,10);
- $pass = password_hash($password, PASSWORD_DEFAULT);
- $update = mysqli_query($con, "UPDATE users SET password = '$pass' WHERE email = '$email'");
- if ($update == 1) {
- $mail = new PHPMailer(true); // Passing `true` enables exceptions
- try {
- //Server settings
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'cpanel04.indocenter.co.id'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'admin@kiducation.id'; // SMTP username
- $mail->Password = 'Kiducationadmin123'; // SMTP password
- $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 465; // TCP port to connect to
-
- //Recipients
- $mail->setFrom('admin@kiducation.id', 'Kiducation.id');
- $mail->addAddress($email); // Add a recipient
-
- //Attachments
- // $mail->addAttachment('images/testi-1.jpg'); // Add attachments
- // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
-
- //Content
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Forgot Password';
- $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';
-
- $mail->send();
- } catch (Exception $e) {
- echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
- }
- header("location:../login.php");
- }
- } else {
- $_SESSION['error'] = "Email belum terdaftar";
- header("location:../forgotPassword.php");
- }
-
- /*
- else:
- $_SESSION['error'] = "Robot verification failed, please try again.";
- header("location:../index.php");
- endif;
- */
- }
- mysqli_close($con);
- ?>