内容导航:{ int number char code string checkCode = String Empty System Random random =,在IP地址的四段号码中,{ int x = random Next(image Width) int y = random Next(image Height) image,random Next(image Height) int y = random Next(image Height) g DrawLine(new
  • C中生成验证码的类
  • IP地址C类指的是什么
  • 如何做到C程序进行验证码识别
  • 如何用c或c生成类似验证码的图片
  • {image}

    一、C中生成验证码的类

    在很多网站中都会用到验证码的功能来防止非肆迹法注册用户 下面我就提供一个生成验证码的类

    代码如下 using System using System Data using System Configuration using System Collections 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 Drawing

    public partial class checkcode System Web UI Page { protected void Page_Load(object sender EventArgs e)

    { CreateCheckCodeImage(GenerateCheckCode()) }

    private string GenerateCheckCode()

    { int number char code string checkCode = String Empty System Random random = new Random()

    for (int i = i < i++)

    { number = random Next()

    if (number % == )

    code = (char)( + (char)(number % )) else code = (char)( A + (char)(number % ))

    checkCode += code ToString() } Response Cookies Add(new HttpCookie( CheckCode checkCode)) return checkCode }

    private void CreateCheckCodeImage(string checkCode)

    { if (checkCode == null || checkCode Trim() == String Empty)

    return System Drawing Bitmap image = new System Drawing Bitmap((int)Math Ceiling((checkCode Length * )) ) Graphics g = Graphics FromImage(image) try { //生成随机生成陆伏器Random random = new Random() //清空图片背景色g Clear(Color White) //画图片的背景噪音线for (int i = i < i++)

    { int x = random Next(image Width) int x = random Next(image Width) int y = random Next(image Height) int y = random Next(image Height) g DrawLine(new Pen(Color Black) x y x y ) } Font font = new System Drawing Font( Arial (System Drawing FontStyle Bold | System Drawing FontStyle Italic)) System Drawing Drawing D LinearGradientBrush brush = new System Drawing Drawing D LinearGradientBrush(裂悉并new Rectangle( image Width image Height) Color Blue Color DarkRed f true) g DrawString(checkCode font brush ) //画图片的前景噪音点for (int i = i < 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) image Width image Height ) System IO MemoryStream ms = new System IO MemoryStream() image Save(ms System Drawing Imaging ImageFormat Gif) Response ClearContent() Response ContentType = image/Gif Response BinaryWrite(ms ToArray()) } finally { g Dispose() image Dispose() }

    二 、IP地址C类指的是什么

    IP地址C类IP地址一个C类IP地址是指,在IP地址的四段号码中 ,前三段号码为网络号码,剩下的一段号码为本地计算机的号码

    三、如何做到C程序进行验证码识别

    如果是简单的图片验证码,上面仅是数字与字母 ,可以使祥迅用OCR识别,桐搭但是如果是更局宴拿高深的如
    .html 类似的验证码,破解的难度会很高。

    四、如何用c或c生成类似验证码的图片

    24位bmp图片的文件格式是:bitmapfileheader, bitmapinfoheader(32位图中是bv5infoheader),下面是颜色表 ,从底部到上方依次从左到右存储像素点的颤消尺颜色信息 。

    完全可以用C++实现。楼主只需自行做茄高好表示各个字符的16 * 16矩阵,桥灶然后用这个矩阵替换灰色噪声背景即可,就相当于往白板上贴卡片。

    本文版权归趣快排SEO www.SeogurUblog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ▶61910465