public IActionResult GetCaptcha() { CaptchaResponseDto dto = new CaptchaResponseDto(); dto = CaptchaHelper.GenerateCaptcha(); return(Ok(dto)); }
private void Button_Click(object sender, RoutedEventArgs e) { if (!int.TryParse(TxtCaptchaCodeLength.Text, out int length)) { length = 4; } var captchaCode = CaptchaHelper.GenerateCaptchaCode(length); TxtCaptchaCode.Text = captchaCode; if (!int.TryParse(TxtImageWidth.Text, out int imageWidth)) { imageWidth = 200; } if (!int.TryParse(TxtImageHeight.Text, out int imageHeight)) { imageHeight = 50; } var captcha = CaptchaHelper.GenerateCaptcha(captchaCode, imageWidth, imageHeight); var bmp = new BitmapImage(); bmp.BeginInit(); bmp.StreamSource = new MemoryStream(captcha.ByteData); bmp.EndInit(); ImgCaptcha.Source = bmp; ImgCaptcha.Width = imageWidth; ImgCaptcha.Height = imageHeight; }
public IActionResult AppCaptchaData() { try { var captchaData = CaptchaHelper.GenerateCaptcha(); return(new JsonResult(captchaData)); } catch (Exception) { throw; } }