-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgotpassword.php
More file actions
104 lines (93 loc) · 3.6 KB
/
forgotpassword.php
File metadata and controls
104 lines (93 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
require("connection.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
function sendMail($email,$reset_token)
{
require('PHPMailer/PHPMailer.php');
require('PHPMailer/SMTP.php');
require('PHPMailer/Exception.php');
$mail = new PHPMailer(true);
try {
//Configurações do Servidor
$mail->isSMTP(); //Enviar usando SMTP
$mail->Host = 'smtp.gmail.com'; //Definir o servidor SMTP para enviar através
$mail->SMTPAuth = true; //Ativar autenticação SMTP
$mail->Username = 'seguranca.projeto.tcc@gmail.com'; //Nome de usuário SMTP
$mail->Password = 'wxqpimmtqoitijdc'; //Senha SMTP
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Ativar criptografia TLS implícita
$mail->Port = 465; //Porta TCP para se conectar; use 587 se você definiu `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('seguranca.projeto.tcc@gmail.com', 'Site Projeto');
$mail->addAddress($email); //Adicionar um destinatário
//Conteúdo
$mail->isHTML(true); //Definir formato de e-mail para HTML
$mail->Subject = 'Link de redefinição de senha de Projeto Segurança da Informação TCC';
$mail->Body = "Recebemos uma solicitação sua para redefinir sua senha! <br>
Clique no link abaixo: <br>
<a href='http://localhost/login/updatepassword.php?email=$email&reset_token=$reset_token'>
Redefinir senha
</a>";
/*alterar o endereço http://localhost/login/updatepassword.php para
http://localhost/nome da sua pasta ou link aqui/updatepassword.php
para encaminhamento quando houver alterações no link ou nome de pasta!*/
$mail->send();
return true;
}
catch (Exception $e) {
return false;
}
}
if(isset($_POST['send-reset-link']))
{
$query="SELECT * FROM `registered_users` WHERE `email`='$_POST[email]'";
$result=mysqli_query($con,$query);
if($result)
{
if(mysqli_num_rows($result)==1)
{
$reset_token=bin2hex(random_bytes(16));
date_default_timezone_set('Asia/kolkata');
$date=date("Y-m-d");
$query="UPDATE `registered_users` SET `resettoken`='$reset_token',`resettokenexpire`='$date' WHERE `email`='$_POST[email]'";
if(mysqli_query($con,$query) && sendMail($_POST['email'],$reset_token))
{
echo"
<script>
alert('Link de redefinição de senha enviado para o seu Email!');
window.location.href='index.php';
</script>
";
}
else
{
echo"
<script>
alert('Servidor caiu! tente mais tarde');
window.location.href='index.php';
</script>
";
}
}
else
{
echo"
<script>
alert('Email não cadastrado!');
window.location.href='index.php';
</script>
";
}
}
else
{
echo"
<script>
alert('não pode executar a consulta');
window.location.href='index.php';
</script>
";
}
}
?>