您的位置:首页 > 其它

验证码制作之三:通过ASCEE码随机生成4位字符与数字验证码

2010-04-20 22:54 459 查看
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
/// <summary>
/// ValidateCode 的摘要说明
/// </summary>
public class ValidateCode
{
public ValidateCode()
{
}

//通过ASCEE码随机生成4位字符串组成验证码
public string validateCode()
{
//
byte[] bytes = new byte[100];
Random randObj = new Random();
int code;
for (int i = 0; i < 4; i++)
{
code = randObj.Next(44, 122);
bytes[i] = Convert.ToByte(code);
}
ASCIIEncoding ascii = new ASCIIEncoding();
string validateCode = ascii.GetString(bytes,0,4);
return validateCode.ToString();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  random string byte class