Asp.net (C #) implements the invitation code Mechanism

Source: Internet
Author: User

At present, many websites have an invitation code mechanism, such as the open-source community, which can prevent flooding attacks. On the other hand, everyone introduces each other to the website to improve the user level of the website. Maintain a good community environment. This article introduces how to implement the invitation code mechanism. Provides C # source code.

Invitation Code Composition: 1-20080330134035-a21f34a965d1cb65 first: User ID, second: year, month, day, hour, minute, Second, Third: verification code.

The verification code algorithm is: User ID + year, month, day, hour, minute, and second + private key, and the 16-bit MD5 value is used.

Code:

 String T = datetime. Now. tostring ("yyyymmddhhmmss ");
String K = BLL. stringutil. MD5 (user. Identity. Name + T + "b497570b-69a2-4bd1-9380-7e74616795ab", 16 );
TXT. TEXT = string. format ("{0}-{1}-{2}", user. identity. name, T, k); the purpose of adding a private key is to prevent others from learning your algorithm and writing it to the registration machine (of course, it depends on the importance of the website ,) in this way, the invitation code is calculated. In aspx (verify the validity of the invitation code ): <Asp: textbox id = "txtcode" runat = "server" rows = "10"> </ASP: textbox> <asp: requiredfieldvalidator id = "R6" runat = "server" controltovalidate = "txtcode" display = "dynamic" errormessage = "Enter the invitation code" setfocusonerror = "true"> </ASP: requiredfieldvalidator>
<Asp: regularexpressionvalidator id = "regularexpressionvalidator1" runat = "server" controltovalidate = "txtcode"
Display = "dynamic" errormessage = "invitation code format error" setfocusonerror = "true" validationexpression = "\ D +-\ D {14}-[\ da-F] {16 }"> </ASP: regularexpressionvalidator>
Backend CS files (verify the validity of the invitation code ):
   
String [] TMP = txtcode. Text. Split ('-');
Bll. stringutil. MD5 (TMP [0] + TMP [1] + "b497570b-69a2-4bd1-9380-7e74616795ab", 16) = TMP [2]

Then we need to record the used invitation code to the database. Next time we have a new invitation code for verification, we will compare it in the database. If it exists, it indicates that it is a used invitation code, expired.

Related Article

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.