-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccount.php
91 lines (75 loc) · 3.09 KB
/
account.php
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
<?php
// require "db_functions.php";
// require "authenticate.php";
include("header.php");
$error = false;
$success = false;
$loginerror = false;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["nicknameLogin"]) && !empty($_POST["senhaLogin"]) && !empty($_POST["novaSenhaLogin"])) {
$conn = connect_db();
$nicknameLogin = mysqli_real_escape_string($conn,$_POST["nicknameLogin"]);
$senhaLogin = mysqli_real_escape_string($conn,$_POST["senhaLogin"]);
$novaSenhaLogin = mysqli_real_escape_string($conn,$_POST["novaSenhaLogin"]);
if ($senhaLogin == $novaSenhaLogin) {
$error = true;
$error_msg = "A nova senha não pode ser igual à senha atual.";
} else {
$senhaLogin = md5($senhaLogin);
$novaSenhaLogin = md5($novaSenhaLogin);
$sql = "SELECT usuarios.senha FROM usuarios
WHERE nickname = '".$nicknameLogin."';";
$result = mysqli_query($conn, $sql);
if($result) {
$row = mysqli_fetch_assoc($result);
if ($row["senha"] == $senhaLogin) {
$query = "UPDATE usuarios SET senha = '".$novaSenhaLogin."' WHERE nickname = '".$nicknameLogin."' ; ";
$result = mysqli_query($conn, $query);
if ($result) {
$success = true;
$success_msg = "Senha alterada com sucesso";
} else {
$error = true;
$error_msg = "Não foi possível alterar a senha.";
}
} else {
$error = true;
$error_msg = "Senha atual incorreta.";
}
}
}
}
}
?>
<?php if ($success): ?>
<h3 style="color:lightgreen;"><?= $success_msg ?></h3>
<?php endif; ?>
<?php if ($error): ?>
<h3 style="color:red;"><?php echo $error_msg; ?></h3>
<?php endif; ?>
<div id="header">
<div id="colsContainer">
<div class="changeInfo" id="borders">
<br/><br/>
<span class="sub">Bem vindo <?= $nickname ?></span><br>
<br/><br/>
<span id=infoConta"">Informações da conta:</span><br>
<br/>
<span>Nickname: <?= $nickname ?></span><br>
<?php if (isset($email)): ?>
<span>E-mail: <?= $email ?></span><br>
<?php endif; ?>
<?php if (isset($telefone)): ?>
<span>Telefone: <?= $telefone ?></span><br>
<?php endif; ?>
<form id="loginForm" action="account.php" method="POST" class="loginForm">
<input minlength="3" maxlength="20" type="text" placeholder="Nickname" name="nicknameLogin" class="loginInputs"> <br>
<input minlength="8" maxlength="32" required="required" type="password" type="password" placeholder="senha" name="senhaLogin" class="loginInputs">
<input minlength="8" maxlength="32" required="required" type="password" type="password" placeholder="senha" name="novaSenhaLogin" class="loginInputs">
<button id="alterar" class="submit" name="submit" value="alterar">Alterar</button>
<span><br></span><br>
</form>
</div>
</div>
</div>
<?php include("footer.php");?>