มาทำ CAPTCHA ใช้เองดีกว่า 
CAPTCHA คือ ตัวอักษรยึกยือ ไว้กัน bot ใน web site ต่างๆ
ตัวอย่าง captcha จาก http://en.wikipedia.org/wiki/CAPTCHA






ซึ่งเราจะใช้ C# สร้าง Captcha ง่ายๆ แบบของเราเองดังนี้

int count = 0;
Image img;
Random rand = new Random();
for (int ii = 0; ii < 1000; ii++)
{
img = new Bitmap(120, 70);
Graphics g = Graphics.FromImage(img);

int i = rand.Next(10000);
String s = "" + (char)(rand.Next(26) + 65);
s += (char)(rand.Next(26) + 65);
s += i;

g.DrawString(s, new Font("Tahoma", 22, FontStyle.Regular), Brushes.Black, 5, 10);

for (int j = 0; j < 10; j++)
{
int x1, y1, x2, y2;
x1 = rand.Next(26);
x2 = rand.Next(26) + 94;
y1 = rand.Next(70);
y2 = rand.Next(70);

g.DrawLine(new Pen(Color.FromArgb(rand.Next(70), rand.Next(70), rand.Next(70))), x1, y1, x2, y2);

}

g.Flush();
img.Save("D://capcha//" + count + ".PNG", System.Drawing.Imaging.ImageFormat.Png);


String path, key, phone;
// id = Int32.Parse(this.textBox_id.Text);
path = count + ".PNG";
key = s;


string cs = @"server=localhost;userid=root;password=1234;database=yyy";
MySqlConnection conn = new MySqlConnection(cs);

String sql = @"INSERT INTO capcha VALUES (0, '" + path + "','" + key + "' )";
MySqlCommand comm = new MySqlCommand(sql, conn);
conn.Open();
comm.ExecuteNonQuery();


conn.Close();

count++;
}





จะเห็นว่ามีการ เก็บ key ที่ถูกต้องของรูปนั้นๆไว้ใน database ด้วย
ตัวอย่าง captcha ที่ได้จากโปรแกรม


[ view entry ] ( 2344 views )   |  permalink  |  $star_image$star_image$star_image$star_image$star_image ( 3 / 1756 )

<<First <Back | 1 | 2 | 3 | 4 | 5 | Next> Last>>