最新下载
热门教程
- 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);
相关文章
- 完蛋我被美女包围了2玩家试玩后体验感怎么样 好评如潮 07-10
- 描写人物外貌的话50字 07-10
- 英雄联盟新手买什么英雄好-英雄购买推荐2025 07-10
- 死亡搁浅2尼尔BOSS怎么打 尼尔BOSS打法攻略 07-10
- 币安app官网下载 币安app官网v2.25.2下载 07-10
- 解限机有什么段位 段位等级介绍 07-10