protected virtual string GenerateRandomText() { string referenceChars = CaptchaCharacters; int length = CaptchaLength; var stringBuilder = new StringBuilder(length); for (int index = 0; index <= length - 1; ++index) { stringBuilder.Append(referenceChars.Substring(CryptoRandomNumberUtil.GetInt32(0, referenceChars.Length - 1), 1)); } return(stringBuilder.ToString()); }
/// <summary> /// Add a variable level of graphic noise to the image /// /// </summary> private void AddNoise(Graphics graphics1, Rectangle rect) { int num1 = 0; int num2 = 0; switch (BackgroundNoise) { case BackgroundNoiseLevel.None: return; case BackgroundNoiseLevel.Low: num1 = 30; num2 = 40; break; case BackgroundNoiseLevel.Medium: num1 = 18; num2 = 40; break; case BackgroundNoiseLevel.High: num1 = 16; num2 = 39; break; case BackgroundNoiseLevel.Extreme: num1 = 12; num2 = 38; break; } using (var solidBrush = new SolidBrush(NoiseColor)) { int maxValue = Convert.ToInt32(Math.Max(rect.Width, rect.Height) / num2); for (int index = 0; index <= Convert.ToInt32(rect.Width * rect.Height / num1); ++index) { graphics1.FillEllipse(solidBrush, CryptoRandomNumberUtil.GetInt32(0, rect.Width), CryptoRandomNumberUtil.GetInt32(0, rect.Height), CryptoRandomNumberUtil.GetInt32(0, maxValue), CryptoRandomNumberUtil.GetInt32(0, maxValue)); } } }
/// <summary> /// Returns a random point within the specified x and y ranges /// </summary> private PointF RandomPoint(int xmin, int xmax, int ymin, int ymax) { return(new PointF(CryptoRandomNumberUtil.GetInt32(xmin, xmax), CryptoRandomNumberUtil.GetInt32(ymin, ymax))); }
/// <summary> /// Returns a random font family from the font whitelist /// /// </summary> private string RandomFontFamily() { string[] strArray = FontWhitelist.Split(';'); return(strArray[CryptoRandomNumberUtil.GetInt32(0, strArray.Length - 1)]); }