Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Captcha image - ASP.NET

I'm in the process of making my own Captcha check on my website. Everything's working, except I need some blurryness/effects on my text that's not viewable by a webcrawler etc.

Some of the code used to generate the text on the image:

Bitmap BitMap = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");
Graphics g = Graphics.FromImage(BitMap);
g.DrawString(""+RandomNumberString+"", new Font("Tahoma", 40), Brushes.Khaki, new PointF(1, 1));
pictureBox1.Image = BitMap;

Example:

enter image description here

What can I do to get my effects/blurryness on my text?

Thank you!

like image 761
Birdman Avatar asked Oct 26 '11 17:10

Birdman


2 Answers

Why roll out your own captcha when reCAPTCHA is free, accessible (through the audio option, making it usable for people with visual issues) and at the same time helps digitize various publications? There's even a .NET implementation.

Edit:

Seeing how it's for fun, having a look at "An ASP.NET Framework for Human Interactive Proofs" might give you some good ideas. Especially the ImageHipChallenge as it includes image distortion code examples.

For example:

for (int y = 0; y < height; y++)
{
    for (int x = 0; x < width; x++)
    {
        int newX = (int)(x + (distortion * Math.Sin(Math.PI * y / 64.0)));
        int newY = (int)(y + (distortion * Math.Cos(Math.PI * x / 64.0)));
        if (newX < 0 || newX >= width) newX = 0;
        if (newY < 0 || newY >= height) newY = 0;
        b.SetPixel(x, y, copy.GetPixel(newX, newY));
    }
}

Which will move the pixels in a wave like fashion. Such as in the second word of your example.

like image 92
Johannes Kommer Avatar answered Oct 06 '22 00:10

Johannes Kommer


Have a look at this tutorial. There you will find a code example on how to create a CAPTCHA using C# and the DrawString method.

Hope, this helps.

like image 33
Hans Avatar answered Oct 06 '22 00:10

Hans