1、如何在设计网页的时候添加进验证吗?!
不用
<TR vAlign=top>
<TD>
<p align="center"> 验证码:
<%dim num1,rndnum
Randomize
Do While Len(rndnum)<4
num1=CStr(Chr((57-48)*rnd+48))
rndnum=rndnum&num1
loop
session("verifycode")=rndnum
%>
<input class="input" type="text" name="verifycode" size="15" font face="宋体" style="font-size: 9pt">
<b><span style="background-color: #FFFFFF"><font color=#000000><%=session("verifycode")%></font></span></b> </TD>
</TR>
应该就好了
如果不行,可以去参考别人的源代码!
2、网页设计中如何编写验证码?
在服务器端生成随机数,存在session里面,然后把带有数字的图片返回到客户端;
客户端提交数据时判断输入的验证码是否与服务器端的一致;
这样可以达到防止恶意攻击的目的.
3、关于网页上的验证码,用VC怎么做识别
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class GenerateCheckCode : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
string chkCode = string.Empty;
//颜色列表,用于验证码、噪线、噪点
Color[] color =...{ Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Brown, Color.DarkBlue };
//字体列表,用于验证码
string[] font =...{ "Times New Roman", "MS Mincho", "Book Antiqua", "Gungsuh", "PMingLiU", "Impact" };
//验证码的字符集,去掉了一些容易混淆的字符
char[] character =...{ '2', '3', '4', '5', '6', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y' };
Random rnd = new Random();
//生成验证码字符串
for (int i = 0; i < 4; i++)
...{
chkCode += character[rnd.Next(character.Length)];
}
Bitmap bmp = new Bitmap(100, 40);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
//画噪线
for (int i = 0; i < 10; i++)
...{
int x1 = rnd.Next(100);
int y1 = rnd.Next(40);
int x2 = rnd.Next(100);
int y2 = rnd.Next(40);
Color clr = color[rnd.Next(color.Length)];
g.DrawLine(new Pen(clr), x1, y1, x2, y2);
}
//画验证码字符串
for (int i = 0; i < chkCode.Length; i++)
...{
string fnt = font[rnd.Next(font.Length)];
Font ft = new Font(fnt, 18);
Color clr = color[rnd.Next(color.Length)];
g.DrawString(chkCode[i].ToString(), ft, new SolidBrush(clr), (float)i * 20 + 8, (float)8);
}
//画噪点
for (int i = 0; i < 100; i++)
...{
int x = rnd.Next(bmp.Width);
int y = rnd.Next(bmp.Height);
Color clr = color[rnd.Next(color.Length)];
bmp.SetPixel(x, y, clr);
}
//清除该页输出缓存,设置该页无缓存
Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0);
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.AppendHeader("Pragma", "No-Cache");
//将验证码图片写入内存流,并将其以 "image/Png" 格式输出
MemoryStream ms = new MemoryStream();
try
...{
bmp.Save(ms, ImageFormat.Png);
Response.ClearContent();
Response.ContentType = "image/Png";
Response.BinaryWrite(ms.ToArray());
}
finally
...{
//显式释放资源
bmp.Dispose();
g.Dispose();
}
}
}
使用方法如下:
新建名为 GenerateCheckCode.aspx 的文件,将上述代码拷贝到代码文件 GenerateCheckCode.aspx.cs
在需要验证码的地方放置语句 <asp:Image ID="img1" runat="server" ImageUrl="~/GenerateCheckCode.aspx" /> 即可。
4、如何用c语言实现验证码的校验?
什么校验方法?
CRC检验如下:
#include<stdio.h>
int binaryToDec(char *str)
{
unsigned n=0;
while(*str!='\0')
{
if(*str<'0'||*str>'9')return -1;
n=n*2+(*str-'0');
str++;
}
return n;
}
void printBinary(int n)
{
if(n>1)printBinary(n/2);
printf("%d",n%2);
}
void main()
{
unsigned n,m,CRC=0x1A8000,fD=0x100000;
char CRC16[32];
while(1)
{
printf("输入16位校验码:");
gets(CRC16);
n=binaryToDec(CRC16);
if(n>65535)
printf("输入值过长,请重新输入\n");
else break;
}
n<<=5;//n左移5位
m=n;//m等于
while(fD>0x20)
{
while( !(m&fD) && !(CRC&1) )//保证被除数第一位为1
{
CRC>>=1;//除数右移一位
fD>>=1;//被除数首位的标志位右移一位
}
m=m^CRC;//被除数与除数相异或
}
n+=m;//模二余数相加
printf("输出21位校验码:");
printBinary(n);
printf("\n");
getchar();
}
5、在visual studio2010中的Web项目设计中怎么添加验证码这个功能
做一个公共类,或者公共页面,专门用来生成 随机码,每次提取一组,存入Session ,生成验证码图片。调用时将输入的值与存入的值对比即可。点击刷新验证码就是重新获取生成一次,重新存入Session。。
private void CreateCheckCode()
{
string checkCode = GetRandWord(5);
Response.Cookies.Add(new HttpCookie("CheckCode", checkCode));
CreateCheckImage(checkCode);
}
/// <summary>
/// 生成验证码图片
/// </summary>
/// <param name="checkCode"></param>
private void CreateCheckImage(string checkCode)
{
if ((checkCode != null) && !(checkCode.Trim() == string.Empty))
{
Bitmap image = new Bitmap((int)Math.Ceiling((double)(checkCode.Length * 12.5)), 0x14);
Graphics g = Graphics.FromImage(image);
try
{
int i;
Random random = new Random();
g.Clear(Color.White);
for (i = 0; i < 0x19; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
Font font = new Font("Arial", 12f, FontStyle.Italic | FontStyle.Bold);
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(checkCode, font, brush, (float)2f, (float)2f);
for (i = 0; i < 100; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
MemoryStream ms = new MemoryStream();
image.Save(ms, ImageFormat.Gif);
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = "image/Gif";
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}
}
/// <summary>
/// 随机数
/// </summary>
/// <param name="length">长度</param>
/// <returns></returns>
private static string GetRandWord(int length)
{
string checkCode = string.Empty;
Random random = new Random();
for (int i = 0; i < length; i++)
{
char code;
int number = random.Next();
if ((number % 2) == 0)
{
code = (char)(0x30 + ((ushort)(number % 10)));
}
else
{
code = (char)(0x41 + ((ushort)(number % 0x1a)));
}
checkCode = checkCode + code.ToString();
}
return checkCode;
}
6、网页设计中怎样插入验证码
你参考下
http://.baidu.com/question/299956539.html
7、请问C语言验证码代码怎么打?
用strcmp函数比较两个字符串,你上图一个生成的字符串,另一个输入的字符串,把这两个传递到函数里,函数返回0就说明两个字符串相等,输入正确,反之输入错误。(头文件导入string.h)。
8、用C#编写网页怎么生成验证码
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace News.Controllers
{
public class ImageCodeController : Controller
{
//
// GET: /ImageCode/
public ActionResult Index()
{
return View();
}
#region 生成图片验证码
/// <summary>
/// 比较图片中的字符和用户输入的字符
/// </summary>
/// <param name="uCode"></param>
/// <returns></returns>
public string GetCodeResult(string uCode)
{
string oldcode = Session["oldcode"] as string;
if (uCode.ToLower() == oldcode.ToLower())
{
return "yes";//用户输入正确
}
else
{
return "no";//用户输入错误
}
}
/// <summary>
/// 生成指定长度的字符串
/// </summary>
/// <returns></returns>
public ActionResult SecurityCode()
{
string code = CreateRandomCode(4); //验证码的字符为4个
Session["oldcode"] = code;//生成后,存在session中,用于和用户输入的值比较
return File(CreateValidateGraphic(code), "image/Jpeg");
}
/// <summary>
/// 生成随机的字符串
/// </summary>
/// <param name="codeCount"></param>
/// <returns></returns>
public string CreateRandomCode(int codeCount)
{
string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,a,b,c,d,e,f,g,h,i,g,k,l,m,n,o,p,q,r,F,G,H,I,G,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,s,t,u,v,w,x,y,z";
string[] allCharArray = allChar.Split(',');
string randomCode = "";
int temp = -1;
Random rand = new Random();
for (int i = 0; i < codeCount; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
}
int t = rand.Next(35);
if (temp == t)
{
return CreateRandomCode(codeCount);
}
temp = t;
randomCode += allCharArray[t];
}
return randomCode;
}
/// <summary>
/// 创建验证码图片
/// </summary>
/// <param name="validateCode"></param>
/// <returns></returns>
public byte[] CreateValidateGraphic(string validateCode)
{
Bitmap image = new Bitmap((int)Math.Ceiling(validateCode.Length * 16.0), 27);
Graphics g = Graphics.FromImage(image);
try
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的干扰线
for (int i = 0; i < 25; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Silver), x1, x2, y1, y2);
}
Font font = new Font("Arial", 13, (FontStyle.Bold | FontStyle.Italic));
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(validateCode, font, brush, 3, 2);
//画图片的前景干扰线
for (int i = 0; i < 100; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
//保存图片数据
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Jpeg);
//输出图片流
return stream.ToArray();
}
finally
{
g.Dispose();
image.Dispose();
}
}
#endregion
}
}
----------------------控制器(上)------页面(下)-------------------------------
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/js/jquery-1.7.2.min.js"></script>
</head>
<body>
<div>
<img src="/ImageCode/SecurityCode" id="imageclick" onclick="this.src=this.src+'?'" />
<input type="text" value="" id="uCode" />
<a href="javaScript:;" id="click">确定</a>
</div>
</body>
</html>
<script type="text/javascript">
$("#click").click(function () {
//用户输入
var uCode = $.trim($("#uCode").val());
//图片中显示的
//获取点击图片后获取的值,并和用户输入的值进行比较
$.post("/ImageCode/GetCodeResult", { uCode: uCode }, function (data) {
if (data == "yes") {
alert("yes");
} else {
alert("验证码输入错误,请重新输入");
//$("#imageclick").click();//错误后,自动点击图片,生成下一个验证码(可选)
}
});
});
</script>
9、怎样实现输入验证码呢?要用C语言的
#include <stdio.h>
#include <string.h>
main()
{
char a[15],i=3;
do{
printf("Password:");
gets(a);
if(strcmp(a,"hello")==0) break;//这里请连到你的密码文件或者是连接到数据库验证,这里是 hello
}while(--i);
if(i==0) printf("Input errer 3 num.System close!\n");
else
{
//这里写入你密码正内确要执行容的代码
}
}