C#,asp.net Implement invitation code mechanism

Source: Internet
Author: User
Tags time and seconds

Now many sites have an invitation code mechanism, such as open source community, on the one hand can prevent irrigation, on the other hand, we are introducing each other to join the site to enhance the site user level. Maintain a good community environment. This article introduces the implementation of the invitation code mechanism. Provides C # source code.

Invitation code Composition: 1-20080330134035-A21F34A965D1CB65 First is: The user number, the second is the month and a minute, the third is the checksum code.

Check code algorithm: User number + month-day time and seconds + private key, take 16-bit MD5 value.

Code:


Code highlighting produced by Actipro Codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> 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 the private key is to prevent others know your algorithm, write the registration machine (of course, also depends on the importance of the site,) so that the calculation of the invitation code. Here is validation of the invitation code validity: aspx:

Code highlighting produced by Actipro Codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> < Asp:textbox ID = "Txtcode" runat = "server" Rows = "Ten" ></Asp:textbox >< Asp:requiredfieldvalidator ID = "R6" runat = "server" ControlToValidate = "Txtcode" Display = "Dynamic" errormessage = "Please fill in the invitation code" SetFocusOnError = "True" & gt;</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 > Background cs Files:

Code highlighting produced by Actipro Codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> string [] tmp = TxtCode.Text.Split ('-');
Bll. STRINGUTIL.MD5 (tmp[0] + tmp[1] + "B497570b-69a2-4bd1-9380-7e74616795ab",) = = tmp[2]

Validates the legality of the invitation code. And then to the use of the invitation code records to the database, the next time there is a new invitation code to verify the time, to the database to compare, the existence of words, said to be used the invitation code, has 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.