最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
防止自动注册代码(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);
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);
相关文章
- 逆水寒手游五子棋残局三十四怎么过 05-02
- 原神仆人相关成就解锁方法 05-02
- 原神4.6版本深渊打法心得 05-02
- 逆水寒手游五子棋残局三十三怎么过 05-02
- 原神4.6深境螺旋12层攻略 05-02
- 原神微风饮游第三天怎么完成 原神微风饮游网页活动第三天攻略 05-02