This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangepw.php
133 lines (128 loc) · 3.7 KB
/
changepw.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
<?php session_start(); ?>
<?php
require_once("./includes/connect.php");
include("./includes/function.php");
include("./includes/header.php");
include("./includes/sidebar-a.php");
?>
<div class="noidung">
<?php
// Kiểm tra đăng nhập
if(isset($_SESSION['user_level']))
{
// Check ID USER
if ($id = validate_id($_SESSION['uid']))
{
// GET thông tin người dùng
$errors = array();
$get = "SELECT user_name, password FROM users WHERE user_id = '$id' LIMIT 1";
$getok = mysql_query($get) or die("SAI SQL");
// Kiểm tra người dùng có trong CSDL không?
if (mysql_num_rows($getok) > 0)
{
$rows = mysql_fetch_assoc($getok);
}
else
{
echo "<script>alert('Không tìm thầy người dùng!')</script>";
echo "<script>window.location.href='index.php'</script>";
}
// Xử lý Form
if (isset($_POST['dongy']))
{
// xử lý thông tin đổi mật khẩu
if (empty($_POST['old_pw']))
{
$errors[] = "null_oldpw";
}
elseif ($_POST['old_pw'] != $rows['password'])
{
$errors[] = "false_oldpw";
}
elseif (empty($_POST['new_pw']))
{
$errors[] = "null_newpw";
}
elseif (empty($_POST['pre_pw']))
{
$errors[] = "null_prepw";
}
elseif ($_POST['new_pw'] != $_POST['pre_pw'])
{
$errors[] = "false_prepw";
}
else
{
$matkhau = checkData($_POST['pre_pw']);
}
// Update Password
if (empty($errors))
{
$uppw = "UPDATE users SET password = '$matkhau' WHERE user_id = '$id' LIMIT 1";
$pwok = mysql_query($uppw) or die("SAI SQL");
if (mysql_affected_rows($dbc) == 1)
{
echo "<script>alert('Mật khẩu của bạn đã được thay đổi.')</script>";
echo "<script>window.location.href='index.php'</script>";
}
else
{
echo "<script>alert('Không thể đổi mật khẩu.')</script>";
}
}
}
?>
<fieldset>
<legend>Đổi mật khẩu</legend>
<form action="" method="post">
<div>
<label>Tên đăng nhập:</label>
<input type="text" name="" value="<?php echo $rows['user_name']; ?>" disabled>
</div>
<div>
<label>Mật khẩu hiện tại:</label>
<input type="password" name="old_pw" value="">
<?php
checkError($errors, 'null_oldpw', '<span class="warning"> Hãy nhập mật khẩu hiện tại.</span>');
checkError($errors, 'false_oldpw', '<span class="warning"> Mật khẩu hiện tại không đúng.</span>');
?>
</div>
<div>
<label>Mật khẩu mới:</label>
<input type="password" name="new_pw" value="">
<?php
checkError($errors, 'null_newpw', '<span class="warning"> Hãy nhập mật khẩu mới.</span>');
?>
</div>
<div>
<label>Nhập lại mật khẩu mới:</label>
<input type="password" name="pre_pw" value="">
<?php
checkError($errors, 'null_prepw', '<span class="warning"> Hãy nhập lại mật khẩu mới.</span>');
checkError($errors, 'false_prepw', '<span class="warning"> Mật khẩu không khớp.</span>');
?>
</div>
<div>
<input type="submit" name="dongy" value="Hoàn tất">
<input type="reset" name="canle" value="Nhập lại">
</div>
</form>
</fieldset>
<?php
}
else
{
// ID False
echo "<script>alert('Người dùng không tồn tại!')</script>";
echo "<script>window.location.href='index.php'</script>";
}
}
else
{
// Chưa login
echo "<script>alert('Hãy đăng nhập để đổi mật khẩu!')</script>";
echo "<script>window.location.href='index.php'</script>";
}
?>
</div><!-- end noidung -->
<?php include("./includes/footer.php"); ?>