forked from etng/youbbs
/
login.php
executable file
·138 lines (114 loc) · 5.99 KB
/
login.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
<?php
define('IN_SAESPOT', 1);
define('CURRENT_DIR', pathinfo(__FILE__, PATHINFO_DIRNAME));
include(CURRENT_DIR . '/config.php');
include(CURRENT_DIR . '/common.php');
require_once(CURRENT_DIR . '/include/GoogleAuth/GoogleAuth.php');
/*
// 屏蔽下面几行可以通过 用户名和密码 登录
if(($options['qq_appid'] && $options['qq_appkey']) || ($options['wb_key'] && $options['wb_secret'])){
header("content-Type: text/html; charset=UTF-8");
echo '请用 ';
if($options['wb_key'] && $options['wb_secret']){
echo ' <a href="/wblogin">微博登录</a>';
}
if($options['qq_appid'] && $options['qq_appkey']){
echo ' <a href="/qqlogin">QQ登录</a>';
}
echo ' <a href="/">返回首页</a>';
exit;
}
*/
if($cur_user){
// 如果已经登录用户无聊打开这网址就让他重新登录吧
setcookie("cur_uid", '', $timestamp-86400 * 365, '/');
setcookie("cur_uname", '', $timestamp-86400 * 365, '/');
setcookie("cur_ucode", '', $timestamp-86400 * 365, '/');
$cur_user = null;
$cur_uid = '';
}
$name = '';
$errors = array();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
//if(empty($_SERVER['HTTP_REFERER']) || $_POST['formhash'] != formhash() || preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) !== preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])) {
//exit('403: unknown referer.');
// }
$name = addslashes(strtolower(trim($_POST["name"])));
$pw = addslashes(trim($_POST["pw"]));
$gcode = $_POST["gauth"];
$seccode = intval(trim($_POST["seccode"]));
if($name && $pw && $seccode){
if(strlen($name)<21 && strlen($pw)<32){
if(preg_match('/^[a-zA-Z0-9\x80-\xff]{4,20}$/i', $name)){
if(preg_match('/^[0-9]{4,20}$/', $name)){
$errors[] = '名字不能全为数字';
}else{
error_reporting(0);
session_start();
if($seccode === intval($_SESSION['code'])){
$db_user = $DBS->fetch_one_array("SELECT * FROM yunbbs_users WHERE name='".$name."' LIMIT 1");
if($db_user){
$pwmd5 = encode_password($pw, $db_user['regtime']);
if($pwmd5 == $db_user['password']){
// G Auth Checking
$gsecret = $db_user['gauthsecret'];
if ($gsecret != Null){
if ($gcode){
$ga = new GoogleAuth();
$checkResult = $ga->verifyCode($gsecret, $gcode);
if ($checkResult) {
//设置cookie
$db_ucode = md5($db_user['id'].$db_user['password'].$db_user['regtime'].$db_user['lastposttime'].$db_user['lastreplytime']);
$cur_uid = $db_user['id'];
setcookie("cur_uid", $cur_uid, time()+ 86400 * 365, '/');
setcookie("cur_uname", $name, time()+86400 * 365, '/');
setcookie("cur_ucode", $db_ucode, time()+86400 * 365, '/');
$cur_user = $db_user;
unset($db_user);
header('location: /');
exit('logined');
} else {
$errors[] = '安全码已过期或输入不正确!';
}
}else{
$errors[] = '您已开启二次验证,请输入安全码!';
}
}else{
//设置cookie
$db_ucode = md5($db_user['id'].$db_user['password'].$db_user['regtime'].$db_user['lastposttime'].$db_user['lastreplytime']);
$cur_uid = $db_user['id'];
setcookie("cur_uid", $cur_uid, time()+ 86400 * 365, '/');
setcookie("cur_uname", $name, time()+86400 * 365, '/');
setcookie("cur_ucode", $db_ucode, time()+86400 * 365, '/');
$cur_user = $db_user;
unset($db_user);
header('location: /');
exit('logined');
}
}else{
// 用户名和密码不匹配
$errors[] = '输入的用户名或密码不正确!';
}
}else{
// 没有该用户名
$errors[] = '输入的用户名不正确!';
}
}else{
$errors[] = '输入的验证码不正确!';
}
}
}else{
$errors[] = '名字太长或太短或包含非法字符!';
}
}else{
$errors[] = '用户名或密码太长了!';
}
}else{
$errors[] = '用户名、密码、验证码必填!';
}
}
// 页面变量
$title = '登 录';
$pagefile = CURRENT_DIR . '/templates/default/'.$tpl.'sigin_login.php';
include(CURRENT_DIR . '/templates/default/'.$tpl.'layout.php');
?>