Discuz Passport pass integrated notes

Source: Internet
Author: User

It's too simple, but it takes a long time to remember. It's a waste of half an hour to find information. I have a deep understanding that good memory is not as bad as writing !! Paste the passport text block today to prevent future forgetting !! Remember, it takes time to find the information you need online !!!!!!


Passport pass integrationArticle 1: Principles of Integration

Please note: the possible consequences of failed integration ----- dz forum cannot be logged on, cannot be managed
Solution:
Step 1: Go to the dz database table cdb_settings and find the following rows and change them
Setting.gif(4.3 KB)

Step 2: delete the dz installation directory/forumdata/cache/cache_settings.php
Step 3: Access the Forum again


Login and registration Integration Process
The user submits the account password information from the login or registry ticket ==>
The Main Station Program checks user login or registration. If the registration succeeds (a new user needs to be generated for registration), then ==>
Set the cookie or session of the main site itself ==>
Url transfer the returned address forward and encoded user information and other information to dz/api/passport. php

Before integration Please carefully read the official passport Technical Documentation: http://www.discuz.net/usersguide/advanced_passport.htmCopy content to clipboardCode:<? Php
// Save this document as login. php
// First copy the encryption and decryption functions in the interface technical document
// To prevent code from being too messy, I copied it to the end of the document.
// Assume that the UserName field is UserName, the password field is Pwd, And the Email field is Email.
// The registration page implementation method is similar. You can implement it on your own. Add QQ to question: 2666556

$ Act = (isset ($ _ GET ['ac'])? $ _ GET ['ac']: "login ";
If (function_exists ($ act) $ act (); else login ();

Function login ()
{
$ ErrMsg = UserCheck ();
If ($ ErrMsg! = "") Echo $ ErrMsg;
// Add the code that shows your login form to the end, as shown in figure
?>
<Form action = login. php? Act = login method = post>
Username: <input name = username>
Password: <input name = password>
<Input name = submit type = submit value = login> </form>
<? Php

} // End function

Function logout () // logout
{
$ Passportkey = "1234567890"; // replace it with the passportkey set for your forum pass.
$ Auth = $ _ COOKIE ['auth'];
Setcookie ("auth", "", time ()-3600 );
$ Forward = $ _ GET ['forward '];
If ($ forward = "") $ forward = ".../index. php"; // replace it with the absolute or relative address of your homepage.
$ Verify = md5 ('logout'. $ auth. $ forward. $ passportkey );
$ Auth = rawurlencode ($ auth );
$ Forward = rawurlencode ($ forward );
Header ("Location: bbs/api/passport. php? Action = logout & auth = $ auth & forward = $ forward & verify = $ verify ");
}

Function UserCheck ()
{
$ Passportkey = "1234567890"; // replace it with the passportkey set for your forum pass.

// =============== Verification input ====================================
If (! Isset ($ _ POST ['submit ']) return; // the button of the login form needs to have the same name
$ Usnm = $ _ POST ['username']; // replace username with the user name field in your login form
$ Pwd = $ _ POST ['Password']; // replace password with the password field in your login form
If ($ usnm = "") return ", enter the user name! ";
If ($ pwd = "") return ", enter the password! ";

// =========== Database processing ========================================
$ Db = mysql_connect ("localhost", "root ","");
Mysql_select_db ("your_db_name ");
$ SQL = "Select * from 'user' where UserName = '". $ usnm. "'limit 1 ";
$ Rs = mysql_query ($ SQL, $ db );
$ Row = mysql_fetch_array ($ rs );
If (! $ Row) return "this user does not exist ";
If ($ row ["Pwd"]! = Md5 ($ pwd) return "Incorrect password ";
Mysql_free_result ($ rs );

// =================== Header to bbs ======================================
$ Member = array
(
'Time' => time (),
'Username' => $ row ["username"],
'Password' => $ row ["Pwd"],
'Email '=> $ row ["email"]
);
$ Auth = passport_encrypt (passport_encode ($ member), $ passportkey );
Setcookie ("auth", $ auth, ($ _ POST ["Cookie"]? Time () + (int) $ _ POST ["Cookie"]: 0 ));
$ Forward = $ _ POST ['forward '];
If ($ forward = "") $ forward = ".../index. php ";
$ Verify = md5 ('login'. $ auth. $ forward. $ passportkey );
$ Auth = rawurlencode ($ auth );
$ Forward = rawurlencode ($ forward );
Header ("Location: bbs/api/passport. php? Action = login & auth = $ auth & forward = $ forward & verify = $ verify ");

}


// ================================================ ======================================
// ================== The copied Functions ==========
Function passport_encrypt ($ txt, $ key ){
Srand (double) microtime () * 1000000 );
$ Encrypt_key = md5 (rand (0, 32000 ));
$ Ctr = 0;
$ Tmp = '';
For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
$ Ctr = strlen ($ encrypt_key )? 0: $ ctr;
$ Tmp. = $ encrypt_key [$ ctr]. ($ txt [$ I] ^ $ encrypt_key [$ ctr ++]);
}
Return base64_encode (passport_key ($ tmp, $ key ));
}

Function passport_decrypt ($ txt, $ key ){
$ Txt = passport_key (base64_decode ($ txt), $ key );
$ Tmp = '';
For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
$ Tmp. = $ txt [$ I] ^ $ txt [++ $ I];
}
Return $ tmp;
}

Function passport_key ($ txt, $ encrypt_key ){
$ Encrypt_key = md5 ($ encrypt_key );
$ Ctr = 0;
$ Tmp = '';
For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
$ Ctr = strlen ($ encrypt_key )? 0: $ ctr;
$ Tmp. = $ txt [$ I] ^ $ encrypt_key [$ ctr ++];
}
Return $ tmp;
}

Function passport_encode ($ array ){
$ Arrayenc = array ();
Foreach ($ array as $ key => $ val ){
$ Arrayenc [] = $ key. '='. urlencode ($ val );
}
Return implode ('&', $ arrayenc );

}
// ================================================ ==========================================
// =========================================================== ==================================
?>

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.