يوميات مقالات تعليقات تعليقات خارجية
 
السلام عليكم، أهلا بك في صفحتي الشخصية... الساعة الآن 6:41 PM دقيقة بتوقيت الرياض
 
 

لا أعتقد انه يوجد انسان في الإنترنت لم تواجه صورة مرسوم عليها أرقام و حروف بطريقة مشوهة في موقع ما، فمواقع مثل Yahoo و Hotmail و كذلك بعض المدونات في Blogger تستخدم هذه الطريقة التي تسمى كابتشا Captch للتفريق بين الإنسان و البرامج الألية التي تتصفح الإنترنت Robots، و التي يبرمجها مبرمجين سيئين بهدف اختراق الإيميلات بطريقة Brute force او لعمل spam كما هو الحال في بلوقر، هذه التقنية سهلة البرمجة في الدوت نيت، و الكود الذي بالأسفل عبارة عن فئة class تنفذ الفكرة لغة السي شارب #C، يستطيع أي شخص استخدامه بكل بساطة، أو تحسينه لإستخدامه في موقعه.

و قبل عرض الكود، أود أن عرض كيف يمكن استخدام:

 string text ="aB34$";
 CaptchaImage ci = new CaptchaImage(text, 200, 50, "Century Schoolbook");
 MemoryStream m = new MemoryStream();
 ci.Image.Save(m, ImageFormat.Jpeg);

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
namespace CaptchaImage
{
  /// <summary>
  /// Summary description for CaptchaImage.
  /// </summary>
  public class CaptchaImage
  {
    // Public properties (all read-only).
    public string Text
    {
      get
      {
        return this.text;
      }
    }
    public Bitmap Image
    {
      get
      {
        return this.image;
      }
    }
    public int Width
    {
      get
      {
        return this.width;
      }
    }
    public int Height
    {
      get
      {
        return this.height;
      }
    }
    // Internal properties.
    private string text;
    private int width;
    private int height;
    private string familyName;
    private Bitmap image;
    // For generating random numbers.
    private Random random = new Random();
    // ====================================================================
    // Initializes a new instance of the CaptchaImage class using the
    // specified text, width and height.
    // ====================================================================
    public CaptchaImage(string s, int width, int height)
    {
      this.text = s;
      this.SetDimensions(width, height);
      this.GenerateImage();
    }
    // ====================================================================
    // Initializes a new instance of the CaptchaImage class using the
    // specified text, width, height and font family.
    // ====================================================================
    public CaptchaImage(string s, int width, int height, string familyName)
    {
      this.text = s;
      this.SetDimensions(width, height);
      this.SetFamilyName(familyName);
      this.GenerateImage();
    }
    // ====================================================================
    // This member overrides Object.Finalize.
    // ====================================================================
    ~CaptchaImage()
    {
      Dispose(false);
    }
    // ====================================================================
    // Releases all resources used by this object.
    // ====================================================================
    public void Dispose()
    {
      GC.SuppressFinalize(this);
      this.Dispose(true);
    }
    // ====================================================================
    // Custom Dispose method to clean up unmanaged resources.
    // ====================================================================
    protected virtual void Dispose(bool disposing)
    {
      if (disposing)
      // Dispose of the bitmap.
        this.image.Dispose();
    }
    // ====================================================================
    // Sets the image width and height.
    // ====================================================================
    private void SetDimensions(int width, int height)
    {
      // Check the width and height.
      if (width <= 0)
        throw new ArgumentOutOfRangeException("width", width, "Argument out of range, must be greater than zero.");
      if (height <= 0)
        throw new ArgumentOutOfRangeException("height", height, "Argument out of range, must be greater than zero.");
      this.width = width;
      this.height = height;
    }
    // ====================================================================
    // Sets the font used for the image text.
    // ====================================================================
    private void SetFamilyName(string familyName)
    {
      // If the named font is not installed, default to a system font.
      try
      {
        Font font = new Font(this.familyName, 12F);
        this.familyName = familyName;
        font.Dispose();
      }
      catch (Exception ex)
      {
        this.familyName = System.Drawing.FontFamily.GenericSerif.Name;
      }
    }
    // ====================================================================
    // Creates the bitmap image.
    // ====================================================================
    private void GenerateImage()
    {
      // Create a new 32-bit bitmap image.
      Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);
      // Create a graphics object for drawing.
      Graphics g = Graphics.FromImage(bitmap);
      g.SmoothingMode = SmoothingMode.AntiAlias;
      Rectangle rect = new Rectangle(0, 0, this.width, this.height);
      // Fill in the background.
      HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White);
      g.FillRectangle(hatchBrush, rect);
      // Set up the text font.
      SizeF size;
      float fontSize = rect.Height + 1;
      Font font;
      // Adjust the font size until the text fits within the image.
      do
      {
        fontSize--;
        font = new Font(this.familyName, fontSize, FontStyle.Bold);
        size = g.MeasureString(this.text, font);
      }while (size.Width > rect.Width);
      // Set up the text format.
      StringFormat format = new StringFormat();
      format.Alignment = StringAlignment.Center;
      format.LineAlignment = StringAlignment.Center;
      // Create a path using the text and warp it randomly.
      GraphicsPath path = new GraphicsPath();
      path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
      float v = 4F;
      PointF[] points =  { new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) };
      Matrix matrix = new Matrix();
      matrix.Translate(0F, 0F);
      path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
      // Draw the text.
      hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
      g.FillPath(hatchBrush, path);
      // Add some random noise.
      int m = Math.Max(rect.Width, rect.Height);
      for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
      {
        int x = this.random.Next(rect.Width);
        int y = this.random.Next(rect.Height);
        int w = this.random.Next(m / 50);
        int h = this.random.Next(m / 50);
        g.FillEllipse(hatchBrush, x, y, w, h);
      }
      // Clean up.
      font.Dispose();
      hatchBrush.Dispose();
      g.Dispose();
      // Set the image.
      this.image = bitmap;
    }
  }
}
نشر بتاريخ Monday, September 25, 2006 12:00 AM

التعليقات

# re: للتفريق بين الإنسان و الألة CAPTCHA Image سلوى 2/18/2007 4:31 PM

حسناً ,

بالرغم مالـCAPTCHA من مميزات وعيوب؛ هل يمكن كسرها ؟


# re: للتفريق بين الإنسان و الألة CAPTCHA Image حسام 2/19/2007 2:17 PM

امممممممم... سؤال جيد يا سلوى،،،
لا يمكن الحديث عن إمكانية كسر إلا إذا رأينا احد كسرها بالفعل،،،
و يمكنك البحث في قوقل "Break Captcha" و راح تطلع لك مختلف المقالات عن كسر الكابتشا، و من ناحيتي ما اعتقد ان كسرها صعب، لأننا بالفعل تطورنا في خوازميات اكتشاف النص Text Detection... و التعرف على الحروف و الأرقام Character Recongition... لكن حتى لو،، الكابتشا تصعب عملية السبام بشكل كبير، و كل ما كسرت طريقة،، ظهرت طريقة لعرض النص اصعب...
فيه أفكار جديده لعرض الكابتشا نصوص ثلاثية الأبعاد :D
موقع جيد:
http://ocr-research.org.ua/

تحياتي


# نعم تم كسر الكثير من خوارزميات الـ captcha.. HuRrIcAnE 2/4/2009 12:25 PM

بسم الله الرحمن الرحيم

أولاً آسف على تأخر الرد ولكن قد يستفيد أحد قادم ومستقبلياً من المعلومات التي أحملها لكم..
بالنسبه لسؤال سلوى ؟
فإن الجواب اي نعم تم كسر الكثير من الكابتشا..

أرجوا مراجعت موضوعي في هذا المنتدى ليتسنى لكم التحقق من هذه الظاهره..
وهي بعنوان "هل تعتمد على الـ capTCHA فقط في حماية صفحاتك ومنتدياتك..؟ "
http:/ /yee7.com/forums/showthread.php?t=1157


بالإضافة إلى هذه المواقع التي منها ما يقدم خدمة كسر الكابتشا مقابل قيمة مالية لكل موقع أو نوع من الكابتشا..

http://captcha.ru/articles/visual/
http://www.lafdc.com/captcha/


بالتوفيق أخي حسام وانا من متابعي مدونة الرائعه جداً

وفقك الله لما يحبه ويرضاه

أخوك HuRrIcAnE


# re: للتفريق بين الإنسان و الألة CAPTCHA Image بدريه 4/19/2010 6:48 AM

ما شفت شي


العنوان  
الإسم  
الموقع
التعليق   
نص الصورة:
 • التصفح
 » RSS
 

 • المقالات

 » ASP.NET










 • الأرشيف
























 • اليوميات












 • الصور



جميع الحقوق محفوظة،
حسام المقحم 2006م