This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsettings.php
124 lines (109 loc) · 3.3 KB
/
settings.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
include 'includes/header.php';
require 'includes/config.php';
?>
<body>
<?php
if($_SESSION['status'] == "admin" || $_SESSION['status'] == "user")
{?>
<div class="container">
<?php
$page='settings';
include 'includes/navbar.php';
include 'includes/file-nav.php';
?>
<div class="sub-page-main">
<div class="display-menu">
<!-- Or delete just the button if no buttons on the page -->
<!--<button class="btn-display-menu" type='submit' name='dosmth' ><i class="fas fa-trash-alt"></i> button example</button>-->
</div>
<div class="main">
<?php
echo "<h3>Change password:</h3>";
echo "<form method='POST'>";?>
<div class="inputs">
<?php
echo "<input type='password' name='currPass' placeholder='Current Password'></input>";
echo "<input type='password' name='newPass1' placeholder='New Password'></input>";
echo "<input type='password' name='newPass2' placeholder='Repeat new password'></input>";
echo "<button name='submitChange'>Change Password</button>";
?>
</div>
<div class="inputs">
<?php
$currentNick = $_SESSION['nick'];
$currentEmail = null;
$sqlGetEmail = "SELECT email FROM Users WHERE nick='$currentNick'";
$resultsGetEmail = mysqli_query($conn, $sqlGetEmail);
if (mysqli_num_rows($resultsGetEmail) > 0)
{
while($row = mysqli_fetch_assoc($resultsGetEmail))
{
$currentEmail = $row['email'];
break;
}
}
echo "<h3>Change email:</h3>";
echo "<input type='text' name='currEmail' placeholder='Your email' value='".$currentEmail."'></input>";
echo "<button name='submitChangeEmail'>Change Email</button>";
echo "</form>";
?>
</div>
</div>
</div>
<?php
if(isset($_POST['submitChange']))
{
$currentPasswordInput = mysqli_real_escape_string($conn, $_POST['currPass']);
$newPasswordInput1 = mysqli_real_escape_string($conn, $_POST['newPass1']);
$newPasswordInput2 = mysqli_real_escape_string($conn, $_POST['newPass2']);
// root pass $2y$10$/XqDBv6/I.4o.0slXEKskO1wu/JOiKII8qBNNlgYb76yHXBE7p4/q
if(password_verify($currentPasswordInput, $_SESSION['password']))
{
if($newPasswordInput1 == $newPasswordInput2)
{
$hashedNewPassword = password_hash($newPasswordInput1, PASSWORD_DEFAULT);
$currUserId = $_SESSION['id'];
$changePasswordSql = "UPDATE Users SET password='$hashedNewPassword' WHERE id='$currUserId'";
if(mysqli_query($conn, $changePasswordSql))
{
echo "Your password was successfully changed!<br>";
}
else
{
echo "ERROR.<br>"; // niekada neturetu but
}
}
else
{
echo "Your new passwords does not match!<br>";
}
}
else
{
echo "Your old password is wrong!<br>";
}
}
if(isset($_POST['submitChangeEmail']))
{
$userNewEmail = mysqli_real_escape_string($conn, $_POST['currEmail']);
$sqlChangeUsersEmail = "UPDATE Users SET email='$userNewEmail' WHERE nick='$currentNick'";
if(mysqli_query($conn, $sqlChangeUsersEmail))
{
echo "Your email has been changed!<br>";
}
else
{
echo "ERROR!"; //niekad neturetu but
}
}
}
else
{
echo '<meta http-equiv="refresh" content="0; url=./errorAuthorization.shtml" />';
echo "You are not authorised to view this page!<br>";
}
?>
</div>
</body>
</html>