一聚教程网:一个值得你收藏的教程网站

热门教程

防止自动注册代码(from dotnetbips.com)

时间:2022-07-02 12:05:30 编辑:袖梨 来源:一聚教程网

Preventing Automated Web Site Registrations
Introduction
Many heavily trafficked public portals provide features such as free emailing services, on-line storage etc. Webmasters administrating these sites always want to make sure that the users registering with their sites are "real" users instead of automated one. Take an example of MSN registration, when you go to their registration page and fill in the details they display a small randomly generated image with some text. The user is supposed to enter the text in the textbox provided on the form which confirms that the person is physically registering with the site. In this article I will show you how to develop similar mechanism for your ASP.NET applications.
GDI+ and Random class
GDI+ classes allow you to easily generate graphics on the fly and display in the web pages. We will be using these classes along with Random class to develop our solution.
Generating random strings
First we need to device a mechanism that will give us a randomly generated string with each request to the page. Following routine does exactly the same.
public static string GetRandomString(int length)
{
int intZero=0, intNine=0, intA=0, intZ=0,
intCount=0, intRandomNumber=0;
string strRandomString;
Random rRandom =new Random(System.DateTime.Now.Millisecond);
intZero = '0';
intNine = '9';
intA = 'A';
intZ = 'Z';
strRandomString = "";
while (intCount < length)
{
intRandomNumber = rRandom.Next(intZero, intZ);

热门栏目