-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashpw.php
More file actions
21 lines (21 loc) · 761 Bytes
/
Copy pathhashpw.php
File metadata and controls
21 lines (21 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
include "config.php";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username = $_SESSION["username"];
$newPassword = $_POST["password"];
$newPassword = $conn->real_escape_string($newPassword);
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
$sql = "UPDATE users SET password = '$hashedPassword' WHERE username = '$username'";
if ($conn->query($sql) === TRUE) {
echo "Password updated successfully!";
} else {
echo "Error updating password: " . $conn->error;
}
$conn->close();
}
?>