-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangepassword.php
96 lines (66 loc) · 2.53 KB
/
changepassword.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
<?php
session_start();
?>
<?php
if($_SESSION['username']) {
if ($_SESSION['loginas'] == 'faculty'){
$conn = new mysqli("localhost", "root", "", "proctordb");
if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}
$un = $_SESSION['username'];
$sql = "select * from emplogin where `loginid` like '$un'";
$result = $conn->query($sql);
if ($result === false) { die(mysqli_error($conn)); }
if ($result->num_rows > 0){
while($row = $result->fetch_assoc() ){
$password = $row["password"];
}}
$conn->close();
$password1 = $_POST['newpass1'];
$password2 = $_POST['newpass2'];
$currentpassword = $_POST['currentpassword'];
if ($password == $currentpassword){
if ($password1 == $password2){
$conn = new mysqli("localhost", "root", "", "proctordb");
$sql = "UPDATE emplogin SET password='$password1' where loginid like '%$un%'";
$result = $conn->query($sql);
echo '<script>alert("password update sucessfull.");window.location.href= "/online proctor/home/account.php";</script>';
}
else {echo '<script>alert("Passwords Do not match.");window.location.href= "/online proctor/home/account.php";</script>';}
}
else {echo '<script>alert("Password is Invalid!");window.location.href= "/online proctor/home/account.php";</script>';}
}
elseif($_SESSION['loginas'] == 'student'){
$conn = new mysqli("localhost", "root", "", "proctordb");
if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}
$un = $_SESSION['username'];
$sql = "select * from studentlogin where `registernumber` like '$un'";
$result = $conn->query($sql);
if ($result === false) { die(mysqli_error($conn)); }
if ($result->num_rows > 0){
while($row = $result->fetch_assoc() ){
$password = $row["password"];
}}
$conn->close();
$password1 = $_POST['newpass1'];
$password2 = $_POST['newpass2'];
$currentpassword = $_POST['currentpassword'];
if ($password == $currentpassword){
if ($password1 == $password2){
$conn = new mysqli("localhost", "root", "", "proctordb");
$sql = "UPDATE studentlogin SET password='$password1' where registernumber like '%$un%'";
$result = $conn->query($sql);
echo '<script>alert("password update sucessfull.");window.location.href= "/online proctor/home/saccount.php";</script>';
}
else {echo '<script>alert("Passwords Do not match.");window.location.href= "/online proctor/home/saccount.php";</script>';}
}
else {echo '<script>alert("Password is Invalid!");window.location.href= "/online proctor/home/saccount.php";</script>';}
}}
else {
echo "<h1>Please login first .</h1>";
header("location: /online proctor/proctor_login.php");
}
?>