About DISCUZ Login Without pass introduction page 1/2 _ php instance

Source: Internet
Author: User
DISCUZ is the most common forum in China. Although he has a pass to connect to everyone, it is still difficult to unify users. He often needs to create two user tables. First, it is not conducive to registration and management, the second is a waste of databases. Introduction to DISCUZ Login Without pass
DISCUZ is the most common forum in China. Although he has a pass to connect to everyone, it is still difficult to unify users. He often needs to create two user tables. First, it is not conducive to registration and management, the second is a waste of databases.
Recently, a project is also using DISCUZ, So I studied the login of DISCUZ and basically completed the synchronous login. If you are interested, you can study it.
If you write your own system, you can directly use the DISCUZ public file to directly reference include/common. inc. php is the easiest way to reference this file. $ discuz_uid is your user ID, and $ discuz_user is your user name,
If you use your own public file, you need to extract two functions. In global. func. php, there are two functions.
Dsetcookie, and authcode. If you are not lazy, you are copying a function clearcookies. The first one is the COOKIE building function of DISCUZ, and the second is the reversible encryption function of DISCUZ, the third is to clear the COOKIE function. I put it in my own FUNC. PHP file in
Now, let's start writing the method for creating and recognizing cookies.
Function lgoin ($ array)
{
$ Username = $ array ['username'];
$ Password = $ array ['Password'];
$ SQL = "SELECT 'uid', 'Password', 'secques' FROM 'cdb _ members 'WHERE
'Username' = '$ username' and 'Password' = md5 (' $ password ')";
Try {
$ Rs = $ this-> _ db-> query ($ SQL );
} Catch (Exception $ e ){
Exit ("query error, error message:". $ e-> getMessage ());
Return 0;
}
$ Row = $ this-> _ db-> fetch ($ rs); // query whether the login user name and password are correct
If ($ row ){
Dsetcookie ('sid ', '',-2423234234); // cancel sid
$ Secques = $ row ['secques'];
$ Uid = $ row ['uid'];
$ FormPassword = $ row ['Password'];
Dsetcookie ('auth', authcode ("$ formPassword \ t $ secques \ t $ uid", 'encode', '20170'), '0 ');
Return 1;
} Else {
Return 2;
}
}

This is a login function. Let's talk about the key part. After the query, when the information is obtained (the user name and password are correct), we get three pieces of information, UID, PASSWORD, and SECQUES, which are used to create cookies in DISCUZ. The first is the user ID, and the second is the encrypted PASSWORD, the third is the encrypted answer to the question (even if it is not set). DISCUZ needs to prompt the question and answer, and we do not need to log on, so I checked it out. Dsetcookie ('auth', authcode ("$ formPassword \ t $ secques \ t $ uid", 'encode', '20170'), '0 ');
This statement is used to create a user's COOKIE. Needless to say, please note that this statement is '123456'. Note that this is the KEY set during encryption, that is, you need to be the same as your DISCUZ here, so there are three areas to be unified, one is global. func. in php, one is the authcode function you copied, and the other is when you use authcode. At this time, you should be able to log on to the Forum. If you cannot log on, please refer to the following

Current 1/2 page12 next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.