Use discuz's encryption function authcode to prevent fake votes _ PHP Tutorial

Source: Internet
Author: User
Use discuz's encryption function authcode to prevent ticket refreshing. Recently, I made a vote, and we need to take anti-vote measures. But it is difficult to prevent ticket scalping. after all, there are many methods. This method is used to prevent ticket swiping to the maximum extent. First, I made a vote recently. we need to take anti-vote measures. But it is difficult to prevent ticket scalping. after all, there are many methods. This method is used to prevent ticket swiping to the maximum extent.

First, define a string 'www .bkjia.com 'on the foreground page, and then use the authcode function of discuz to generate a string of ciphertext. This string of ciphertext is different each time, for example, it will generate

  • 10884NwIMCg5nDZ24rarNv + nBpsWut6ReT1grxHH4oKSdvgPmXJ0z2jEuePCe
  • Bytes

However, after decoding in the background, the restored plaintext will eventually be changed back to 'www .bkjia.com '. using this, we can determine on the server that, if the returned ciphertext is not the string after decoding, we cannot vote.

Discuz's authcode function can be said to have made significant contributions to the Chinese PHP community. Including Kangsheng's own products, and most Chinese companies that use PHP use this function for encryption. authcode uses exclusive or operations for encryption and decryption.

The principle is as follows:

Encryption

  • Plaintext: 1010 1001
  • Key: 1110 0011
  • Ciphertext: 0100 1010

The ciphertext 0100 1010 is obtained, and the decryption must be different from the key or lower.

Decryption

  • Ciphertext: 0100 1010
  • Key: 1110 0011
  • Plaintext: 1010 1001

There is no advanced algorithm, and the key is very important. The key is how to generate the key. Let's take a look at how Kangsheng's authcode works:

 0 verify data validity // substr ($ result, 10, 16) = substr (md5 (substr ($ result, 26 ). $ keyb), 0, 16) verify data integrity // verify data validity. please refer to the unencrypted plaintext format if (substr ($ result, 0, 10) = 0 | substr ($ result, 0, 10)-time ()> 0) & substr ($ result, 10, 16) = substr (md5 (substr ($ result, 26 ). $ keyb), 0, 16) {return substr ($ result, 26) ;}else {return '';}} else {// Save the dynamic key in the ciphertext, this is also the reason why different ciphertext texts can be decrypted in the same plain text. // because the encrypted ciphertext may be special characters, the replication process may be lost. Base64 encoded return $ keyc. str_replace ('=', '', base64_encode ($ result);} // encrypt echo authcode (" www.bkjia.com ", 'encoding '); // decrypt echo authcode ("www.bkjia.com", 'encoding'); // echo authcode ("authorization + fC + GKP9Efq6yWeAAvdQFq + D");?>

Bytes. But it is difficult to prevent ticket scalping. after all, there are many methods. This method is used to prevent ticket swiping to the maximum extent. First in...

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.