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 object GetCaptchaImage(string key) { string captchaCode = CaptchaHelper.GenerateCaptchaCode(); var result = CaptchaHelper.GetImage(116, 36, captchaCode); MemoryCacheService.Default.SetCache(key, captchaCode, 5); return(new FileStreamResult(new MemoryStream(result.CaptchaByteData), "image/png")); }
public IActionResult GetCaptchaImage() { string captchaCode = CaptchaHelper.GenerateCaptchaCode(); var result = CaptchaHelper.GetImage(116, 36, captchaCode); HttpContext.Session.SetString(CaptchaCodeSessionName, captchaCode); return(new FileStreamResult(new MemoryStream(result.CaptchaByteData), "image/png")); }
/// <summary> /// 获取验证码 /// </summary> /// <returns></returns> public IActionResult CheckCode() { string captchaCode = CaptchaHelper.GenerateCaptchaCode(); var result = CaptchaHelper.GetImage(116, 36, captchaCode); HttpContext.Session.SetString("CheckCode", captchaCode); return(File(new MemoryStream(result.CaptchaByteData), "image/png")); }
public IActionResult GetCaptchaImage() { int width = 120; int height = 36; var captchaCode = CaptchaHelper.GenerateCaptchaCode(); var result = CaptchaHelper.GenerateCaptchaImage(width, height, captchaCode); HttpContext.Session.SetString("CaptchaCode", result.CaptchaCode); Stream s = new MemoryStream(result.CaptchaByteData); return(new FileStreamResult(s, "image/png")); }
/// <summary> /// 获取验证码 /// </summary> /// <returns></returns> public IActionResult GetCatchaImage() { //验证码 string captchaCode = CaptchaHelper.GenerateCaptchaCode(); //图片 var result = CaptchaHelper.GetImage(116, 36, captchaCode); //存储验证码 HttpContext.Session.SetString(CaptchaCodeName, captchaCode); //返回图片 return(new FileStreamResult(new MemoryStream(result.CaptchaByteData), "img/png")); }
/// <summary> /// 获取验证码 /// </summary> /// <returns></returns> public async Task <CaptchaResult> GetCaptchaResultAsync() { CaptchaResult captcha; try { captcha = CaptchaHelper.CreateVerifyCodeImage(CaptchaHelper.GenerateCaptchaCode()); } catch (Exception e) { LogHelper.Logger.Fatal(e, "验证码生成 失败"); return(null); } //var captcha = CaptchaHelper.CreateImage(CaptchaHelper.GenerateCaptchaCode()); var uuid = IdWorker.NextId(); var key = CacheKeys.CAPTCHA + uuid; await RedisClient.SetAsync(key, captcha.Captcha, CaptchaExpired); captcha.Uuid = uuid.ToString(); return(captcha); }