Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Form -->
- <form class="text-center formulario" style="color: #757575;" action="recuperar_pass.php" method="POST">
- <!-- Email -->
- <div class="md-form">
- <input type="email" id="materialLoginFormEmail" class="form-control" name="email">
- <label for="materialLoginFormEmail">E-mail</label>
- </div>
- <!-- Sign in button -->
- <div class="text-center mt-4">
- <button class="btn btn-warning btn-lg mt-4" value="enviar">Enviar</button>
- </div>
- </form>
- <?php
- use PHPMailerPHPMailerPHPMailer;
- use PHPMailerPHPMailerException;
- require 'vendor/autoload.php';
- $link = 'mysql:host=localhost;dbname=drivers_parade_club';
- $usuario = 'root';
- $contraseña = '';
- if (array_key_exists('email', $_POST) ) {
- try{
- $pdo = new PDO($link,$usuario,$contraseña);
- $sql = "SELECT email FROM usuarios";
- $st = $pdo-> prepare($sql);
- $st->bindValue(1,$_POST['email']);
- $st->execute();
- if ($resultado = $st->fetch(PDO::FETCH_ASSOC)){
- echo 'Hemos enviado un mail a '.$resultado['email'];
- $token = uniqid();
- $sql = "UPDATE usuarios SET token = '$token' WHERE email = '{$resultado['email']}'";
- try{
- $pdo->exec($sql);
- $mail = new PHPMailer(true); // Passing `true` enables exceptions
- try {
- //Server settings
- $mail->SMTPDebug = 2; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'smtp.gmail.com;'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'user@gmail.com'; // SMTP username
- $mail->Password = 'secret'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587; // TCP port to connect to
- //Recipients
- $mail->setFrom('driversparadeclub@gmail.com', 'Drivers Parade Club');
- //Content
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Recupere su clave';
- $mail->Body = 'Haga click en <a href="https://www.driversparadeclub.org/php/recuperar.php?token='.$token.'">este link</a>';
- $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- $mail->send();
- echo 'Message has been sent';
- } catch (Exception $e) {
- echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
- }
- }catch (PDOException $e){
- echo 'No se ha podido guardar el token: '.$e->getMessage();
- }
- } else{
- echo 'No existe el usuario';
- }
- }catch(PDOException $e){
- echo 'Fallo en la conexión a la base: '.$e->getMessage();
- }
- }
- <?php
- $link = 'mysql:host=localhost;dbname=drivers_parade_club';
- $usuario = 'root';
- $contraseña = '';
- $pdo = new PDO($link,$usuario,$contraseña);
- if (array_key_exists($_GET['token'])){
- $sql ="SELECT id, username FROM usuarios WHERE token = ?";
- $st = $pdo->prepare($sql);
- $st->bindValue (1,$_GET['token']);
- $st->execute();
- if($resultado = $st->fetch(PDO::FETCH_ASSOC)){
- $sql = "UPDATE usuarios SET token = null WHERE id = {$resultado['id']}";
- $pdo->exec($sql);
- ?>
- <h1>Bienvenido <?php echo $resultado['email'];?></h1>
- <form action="recuperar.php" method="post">
- <input type= "hidden" value= "<?php echo $resultado['id'];?>" name="id"/>
- <table>
- <tr>
- <td><label for="newPassword">Ingresa tu nueva contraseña</label></td>
- <td><input type="password" id="newPassword" name="newPassword"/>
- </tr>
- <tr>
- <td colspan="2">
- <input type="submit" value="Enviar"/>
- </td>
- </tr>
- </table>
- </form>
- <?php
- }
- }elseif (array_key_exists('id',$_POST)){
- $sql = "UPDATE usuarios SET pass = ".hash('sha512',$_POST['newPassowrd'])." WHERE id ={$resultado['id']}";
- $pdo->exec($sql);
- echo 'Contraseña cambiada';
- }
Add Comment
Please, Sign In to add comment