-
Notifications
You must be signed in to change notification settings - Fork 0
/
acc_password.php
executable file
·171 lines (160 loc) · 5.33 KB
/
acc_password.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/*
WebNoter 1.0
(C)2024 Bartłomiej "Magnetic-Fox" Węgrzyn!
*/
session_start();
require_once("apic.php");
require_once("helpers.php");
include_once("stringtable.php");
if(!isLoggedIn()) {
header("location: login.php");
exit;
}
$oldPassword = "";
$newPassword = "";
$confirmNewPassword = "";
$passwordChanged = false;
if($_SERVER["REQUEST_METHOD"]=="POST") {
if(empty(trim($_POST["old_password"]))) {
$old_password_err = ST_INVALID_PASSWORD;
}
else {
$oldPassword = trim($_POST["old_password"]);
}
if(empty(trim($_POST["new_password"]))) {
$new_password_err = ST_INVALID_PASSWORD;
}
else {
$newPassword = trim($_POST["new_password"]);
}
if(empty(trim($_POST["confirm_new_password"]))) {
$confirm_new_password_err = ST_INVALID_PASSWORD;
}
else {
$confirmNewPassword = trim($_POST["confirm_new_password"]);
}
if($newPassword != $confirmNewPassword) {
$confirm_new_password_err = ST_DIFFERENT_PASSWORDS;
}
else {
if(empty($oldPassword)) {
$old_password_err = ST_PROVIDE_OLD_PASSWORD;
}
else {
try {
$currentUser=getCurrentUserInfo($_SESSION["credentials"]);
if(changeUserPassword($_SESSION["credentials"],$_SESSION["user_id"],$oldPassword,$newPassword)) {
$passwordChanged = true;
// As I've said in login.php file...
$_SESSION["credentials"]=$currentUser["username"].":".$newPassword;
}
else {
$passwordChange_err = ST_PASSWORD_CHANGE_FAILED.".";
}
}
catch(Exception $e) {
$passwordChange_err = ST_PASSWORD_CHANGE_FAILED." (".json_decode($e->getMessage(), true)["error"].").";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="<?php echo ST_HTMLLANG; ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo ST_WEBNOTER; ?></title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.bundle.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a href="index.php" class="navbar-brand"><?php echo ST_WEBNOTER; ?></a>
<button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<div class="navbar-nav">
<a href="index.php" class="nav-item nav-link"><?php echo ST_MAINPAGE; ?></a>
<a href="notes.php" class="nav-item nav-link"><?php echo ST_NOTES; ?></a>
<a href="user.php" class="nav-item nav-link active"><?php echo ST_USER; ?></a>
<a href="server.php" class="nav-item nav-link"><?php echo ST_SERVER; ?></a>
</div>
<div class="navbar-nav ms-auto">
<?php echo isLoggedIn() ? '' : '<a href="register.php" class="nav-item nav-link">'.ST_REGISTER.'</a>' ?>
<a href="<?php echo isLoggedIn() ? 'logout.php' : 'login.php' ?>" class="nav-item nav-link"><?php echo isLoggedIn() ? ST_LOGOUT : ST_LOGIN ?></a>
</div>
</div>
</div>
</nav>
<div class="container">
<div class="p-2 my-4 bg-light rounded-3">
<?php
echo "<h4>".ST_PASSWORD_CHANGE."</h4>";
if($passwordChanged==false) {
echo "<p>".ST_FILL_TO_CHANGE_PASSWORD."</p>";
if(!empty($passwordChange_err)) {
echo '<div class="alert alert-danger">' . $passwordChange_err . '</div>';
}
echo "<form action=\"".htmlspecialchars($_SERVER["PHP_SELF"])."\" method=\"POST\">";
echo "<div class=\"form-group\">";
echo "<label>".ST_OLD_PASSWORD."</label>";
echo "<input type=\"password\" name=\"old_password\" class=\"form-control ";
echo (!empty($old_password_err)) ? 'is-invalid' : '';
echo "\">";
echo "<span class=\"invalid-feedback\">";
if(!empty($old_password_err)) {
echo $old_password_err;
}
echo "</span>";
echo "</div>";
echo "<div class=\"form-group\">";
echo "<label>".ST_NEW_PASSWORD."</label>";
echo "<input type=\"password\" name=\"new_password\" class=\"form-control ";
echo (!empty($new_password_err)) ? 'is-invalid' : '';
echo "\">";
echo "<span class=\"invalid-feedback\">";
if(!empty($new_password_err)) {
echo $new_password_err;
}
echo "</span>";
echo "</div>";
echo "<div class=\"form-group\">";
echo "<label>".ST_REPEAT_PASSWORD."</label>";
echo "<input type=\"password\" name=\"confirm_new_password\" class=\"form-control ";
echo (!empty($confirm_new_password_err)) ? 'is-invalid' : '';
echo "\">";
echo "<span class=\"invalid-feedback\">";
if(!empty($confirm_new_password_err)) {
echo $confirm_new_password_err;
}
echo "</span>";
echo "</div>";
echo "<div class=\"form-group\">";
echo "<br>";
echo "<input type=\"submit\" value=\"".ST_CHANGE_PASSWORD."\" class=\"btn btn-outline-primary\"> ";
echo "<a href=\"user.php\" class=\"btn btn-outline-secondary\">".ST_CANCEL."</a>";
echo "</div>";
echo "</form>";
}
else {
echo "<div class=\"alert alert-success\">";
echo "<strong>".ST_PASSWORD_CHANGED."</strong> ".ST_YOU_MAY_RETURN_TO_YOUR." <a href=\"user.php\">".ST_USER_PROFILE."</a>.";
echo "</div>";
}
?>
</div>
<hr>
<footer>
<div class="row">
<div class="col-md-6">
<p><?php echo ST_COPYRIGHT; ?></p>
</div>
</div>
</footer>
</div>
</body>
</html>