Guest User

Untitled

a guest
May 27th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7.  
  8. namespace Tienda_Virtual
  9. {
  10. class Captcha
  11. {
  12. private Bitmap _bitmap = new Bitmap(310, 77);
  13.  
  14. public Bitmap bitmap
  15. {
  16. get { return _bitmap; }
  17. set { _bitmap = value; }
  18. }
  19. private string _code = string.Empty;
  20.  
  21. public string code
  22. {
  23. get { return _code; }
  24. set { _code = value; }
  25. }
  26.  
  27. public Captcha()
  28. {
  29. SetRandomizedCode();
  30. SetBitmap();
  31. }
  32.  
  33. private string[] _captcha2 = new string[7];
  34.  
  35. public string[] captcha2
  36. {
  37. get { return _captcha2; }
  38. set { _captcha2 = value; }
  39. }
  40.  
  41. private void SetBitmap()
  42. {
  43. FontStyle style = FontStyle.Italic | FontStyle.Strikeout | FontStyle.Underline | FontStyle.Regular | FontStyle.Bold;
  44. Font font = new Font("Arial", 50f, style);
  45. Graphics GFX = Graphics.FromImage(_bitmap);
  46. GFX.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  47. GFX.FillRectangle(Brushes.LightBlue, 0, 0, _bitmap.Width, _bitmap.Height);
  48. GFX.DrawString(_code, font, Brushes.CornflowerBlue, new Point(-26, -26));
  49. GFX.Transform.Rotate(50f);
  50. }
  51.  
  52. private void SetRandomizedCode()
  53. {
  54. _code = string.Empty;
  55. Random random = new Random();
  56. string combination = "0123456789ABCDEFGHJKLMNOPQRSTUVWXYZ";
  57. StringBuilder captcha = new StringBuilder();
  58. for (int i = 0; i < 7; i++)
  59. {
  60. captcha.Append(combination[random.Next(combination.Length)]);
  61. _captcha2[i] = captcha[i].ToString();
  62. }
  63. _code = captcha.ToString();
  64. }
  65. }
  66. }
Add Comment
Please, Sign In to add comment