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.