-
Notifications
You must be signed in to change notification settings - Fork 2
/
repass.php
145 lines (133 loc) · 4.86 KB
/
repass.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
<?php
include("init.php");
include("config.php");
if (isset($_POST["repass"])) {
$success = FALSE;
if (($_POST["oldpass"] != $_SESSION["tpass"] && md5($_POST["oldpass"]) != $_SESSION["tpass"])||($_POST["newpass"]!=$_POST["repass"])||(strlen($_POST["newpass"]) < 5)) {
header("Location: repass.php?err=1");
}
else $success = TRUE;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Đăng nhập · Chấm bài trực tuyến</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-repass {
max-width: 300px;
padding: 19px 29px 29px;
margin: 0 auto 20px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.form-repass .form-repass-heading,
.form-repass .checkbox {
margin-bottom: 10px;
}
.form-repass input[type="text"],
.form-repass input[type="password"] {
font-size: 16px;
height: auto;
margin-bottom: 15px;
padding: 7px 9px;
}
.form-repass .warning {
font-size: 14px;
color: red;
margin-top: 8px;
text-align: center;
}
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="ico/favicon.png">
</head>
<body>
<div class="container">
<form class="form-repass" method="POST" action="<?php echo $_SERVER['PHP_SELF']?>">
<h2 class="form-repass-heading">Đổi mật khẩu</h2>
<input type="password" name="oldpass" class="input-block-level" placeholder="Mật khẩu cũ">
<input type="password" name="newpass" class="input-block-level" placeholder="Mật khẩu mới (ít nhất 5 ký tự)">
<input type="password" name="repass" class="input-block-level" placeholder="Nhập lại mật khẩu mới">
<div align="center">
<button class="btn btn-large btn-primary" type="submit">Đổi mật khẩu</button>
<a class="btn btn-large btn-primary" href="index.php">Về trang chủ</a>
<div class="warning">
<?php if (isset($_GET['err'])) echo "<strong>LỖI:</strong> Mật khẩu cũ không đúng, mật khẩu mới quá ngắn hoặc nhập không trùng nhau!"; ?>
</div>
</div>
</form>
</div> <!-- /container -->
<?php
if (isset($success) && $success) {
if (!is_file($contestDir . 'tmp.xml')) {
$fi = fopen($contestDir . 'account.xml','r');
$fo = fopen($contestDir . 'tmp.xml','w');
while (!feof($fi)) {
$str = fgets($fi);
if (strpos($str,">".$user['username']."<") > 0) {
fwrite($fo,$str);
$str = fgets($fi);
$str = str_replace(">".$user['password']."<",">".md5($_POST['newpass'])."<",$str);
fwrite($fo,$str);
$str = fgets($fi);
fwrite($fo,$str);
$str = fgets($fi);
$str = str_replace('>0<','>1<',$str);
}
fwrite($fo,$str);
}
fclose($fi);
fclose($fo);
copy($contestDir . 'tmp.xml',$contestDir . 'account.xml');
unlink($contestDir . 'tmp.xml');
$_SESSION['tpass']=md5($_POST['newpass']);
?>
<script>
alert("Đổi mật khẩu thành công");
window.location.assign("index.php");
</script>
<?php
}
else {
?>
<script>
alert("LỖI: Đổi mật khẩu không thành công\n Vui lòng đổi mật khẩu lại!");
window.location.assign("repass.php");
</script>
<?php
}
}
?>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>