开发者

How to make image captcha question with asp.net

开发者 https://www.devze.com 2023-03-26 15:39 出处:网络
What is the best, most effective and yet easiest way of making image captcha security 开发者_如何转开发questions with ASP.net Netframework 4.0 Don\'t reinvent the wheel if you don\'t HAVE to.

What is the best, most effective and yet easiest way of making image captcha security 开发者_如何转开发questions with ASP.net Netframework 4.0


Don't reinvent the wheel if you don't HAVE to.

Use recaptcha.

Here's how to do it in .Net:

http://code.google.com/apis/recaptcha/docs/aspnet.html


I think you are asking how make my own with asp.net not use external. This is what i use and pretty effective

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class AntiSecuirtyImageDrawPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.returnNumer(); 
    }

    private void returnNumer()
    {

        Random num1 = new Random();

        Random num2 = new Random();

        int numQ1 = 0;

        int numQ2 = 0;

        string QString = null;

        numQ1 = num1.Next(1, 90);

        numQ2 = num1.Next(1, 9);

        QString = numQ1.ToString() + " + " + numQ2.ToString() + " = ";

        Session["ABQAnswer"] = numQ1 + numQ2;

        Bitmap bitmap = new Bitmap(num1.Next(70, 125), 22);

        Graphics Grfx = Graphics.FromImage(bitmap);

        Font font = new Font("Arial", 17, FontStyle.Bold, GraphicsUnit.Pixel);

        Rectangle Rect = new Rectangle(0, 0, 125, 50);

        Grfx.FillRectangle(Brushes.DarkBlue, Rect);

        Grfx.DrawRectangle(Pens.PeachPuff, Rect);

        // Border

        Grfx.DrawString(QString, font, Brushes.White, 0, 0);

        Response.ContentType = "Image/jpeg";

        bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

        bitmap.Dispose();

        Grfx.Dispose();

    } 
}

how do i call it

  <div id="ABQImg" style="position: absolute; left: 420px; top: 235px; width: 125px;
            z-index: 44; height: 22px; line-height: 22px; text-align: right;">
            <asp:Image ID="imgABQ" BorderWidth="0px" runat="server" ImageUrl="~/AntiSecuirtyImageDrawPage.aspx" />
        </div>
0

精彩评论

暂无评论...
验证码 换一张
取 消