discuz X3用户登录uc_user_login()函数详解
验证用户登录 discuz x3/source/function/function_member.php中大约35行左右:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
if
(
$isuid
== 3) {
if
(!
strcmp
(dintval(
$username
),
$username
) && getglobal(
'setting/uidlogin'
)) {
$return
[
'ucresult'
] = uc_user_login(
$username
,
$password
, 1, 1,
$questionid
,
$answer
,
$ip
);
}
elseif
(isemail(
$username
)) {
$return
[
'ucresult'
] = uc_user_login(
$username
,
$password
, 2, 1,
$questionid
,
$answer
,
$ip
);
}
if
(
$return
[
'ucresult'
][0] <= 0 &&
$return
[
'ucresult'
][0] != -3) {
$return
[
'ucresult'
] = uc_user_login(
addslashes
(
$username
),
$password
, 0, 1,
$questionid
,
$answer
,
$ip
);
}
}
else
{
$return
[
'ucresult'
] = uc_user_login(
addslashes
(
$username
),
$password
,
$isuid
, 1,
$questionid
,
$answer
,
$ip
);
}
|
这里的uc_user_login()就是去验证登录是否成功:
用户登录:
array uc_user_login(
string username ,
string password,
bool isuid ,
bool checkques ,
integer questionid ,
string answer
)
函数参数
参数 | 含义 |
---|---|
string username | 用户名 / 用户 ID |
string password | 密码 |
bool isuid | 是否使用用户 ID登录 1:使用用户 ID登录 0:(默认值) 使用用户名登录 |
bool checkques | 是否验证安装提问 1:验证安全提问 0:(默认值) 不验证安全提问 |
integer questionid | 安全提问索引 |
string answer | 安全提问答案 |
返回值
值 | 含义 | |
---|---|---|
array | integer [0] | 大于 0:返回用户 ID,表示用户登录成功 -1:用户不存在,或者被删除 -2:密码错 -3:安全提问错 |
string [1] | 用户名 | |
string [2] | 密码 | |
string [3] | ||
bool [4] | 用户名是否重名 |
本接口函数用于用户的登录验证,用户名及密码正确无误则返回用户在 UCenter 的基本数据,否则返回相应的错误信息。如果应用程序是升级过来的,并且当前登录用户和已有用户重名,那么返回的数组中 [4] 的值将返回 1。
附加获取用户数据方法:uc_get_user()
获取用户数据:
array uc_get_user(
string username,
bool isuid
)
函数参数
参数 | 含义 |
---|---|
string username | 用户名 |
bool isuid | 是否使用用户 ID获取 1:使用用户 ID获取 0:(默认值) 使用用户名获取 |
返回值
值 | 含义 | |
---|---|---|
array | integer [0] | 用户 ID |
string [1] | 用户名 | |
string [2] |
本接口函数用于获取用户在 UCenter 的基本数据,如用户不存在,返回值为 integer 的数值 0。
本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/1293562,如需转载请自行联系原作者