-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_password.php
More file actions
33 lines (31 loc) · 899 Bytes
/
change_password.php
File metadata and controls
33 lines (31 loc) · 899 Bytes
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
<?php
session_start();
if(!(isset($_SESSION)) || (empty($_SESSION['user'])))
{
header('Location: '. "index.php" );
}
// Grab User submitted information
$name = $_POST["usrname"];
$oldpass = $_POST["oldpwd"];
$newpass = $_POST["newpwd"];
// Connect to the database
$con = mysql_connect("localhost","root","r00tpass");
// Make sure we connected successfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}
// Select the database to use
mysql_select_db("mysql_db",$con);
$query = "SELECT username, password FROM users WHERE username = \"$name\"";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if($row["password"]==$oldpass)
{
session_start();
$query = "UPDATE users SET password=\"$newpass\" WHERE username = \"$name\"";
$result = mysql_query($query);
}
else
echo 'Password Doesn\'t match';
?>