public void GetCaptchaImage() { var captcha = CaptchaCode.DrawNumberImage(4); Session.Set(CustomConfig.CaptchaSession, captcha.Result); System.Web.HttpContext.Current.Response.ClearContent(); System.Web.HttpContext.Current.Response.ContentType = "image/gif"; System.Web.HttpContext.Current.Response.BinaryWrite(captcha.ImgData); System.Web.HttpContext.Current.Response.End(); }
public void GetSudokuCaptchaImage() { var cap = CaptchaCode.DrawChinaSudokuImage(); byte[] CaptchaData = cap.ImgData; Session.Set(CustomConfig.CaptchaSession, cap.Result); System.Web.HttpContext.Current.Response.ClearContent(); System.Web.HttpContext.Current.Response.ContentType = "image/gif"; System.Web.HttpContext.Current.Response.BinaryWrite(CaptchaData); System.Web.HttpContext.Current.Response.End(); }
public IActionResult OnPost() { User ExistUser = userRepository.Find(LogonUser.Name); if (ExistUser == null) { ModelState.AddModelError("LogonUser.Name", "用户名不存在"); } else if (ExistUser.Password != LogonUser.Password) { ModelState.AddModelError("LogonUser.Password", "用户名或密码错误"); } //else nothing //string captcha = Request.Cookies[Keys.Captcha]; string captcha = HttpContext.Session.GetString(Keys.Captcha); if (captcha != CaptchaCode?.ToUpper()) { ModelState.AddModelError("CaptchaCode", "验证码错误"); //Response.Cookies.Delete(Keys.Captcha); } if (!ModelState.IsValid) { Dictionary <string, string> errors = ModelState.Where(m => m.Value.Errors.Any()).ToDictionary( m => m.Key, m => m.Value.Errors.Select(e => e.ErrorMessage).First()); TempData[Keys.ErrorInPost] = errors; //return RedirectToPage(); return(Redirect(Request.Path.Value)); } CookieOptions cookieOptions = new CookieOptions(); if (RememberMe) { cookieOptions.Expires = DateTime.Now.AddDays(30); } //else nothing Response.Cookies.Append(Keys.UserId, ExistUser.Id.ToString(), cookieOptions); string url = Convert.ToString(RouteData.Values["refererURL"]); //var url1 = Uri.EscapeUriString(url); //var url2 = Uri.EscapeDataString(url); url = Uri.UnescapeDataString(url); return(Redirect(url)); }
private void ValidateCaptcha() { if (webContext.AppConfig.LoginOptions.RequireCaptcha) { string requiredCode = HttpContext.Session.GetString(CaptchaSessionKey); if (string.IsNullOrEmpty(requiredCode) || string.IsNullOrEmpty(CaptchaCode) || !string.Equals(requiredCode, CaptchaCode.Trim(), StringComparison.OrdinalIgnoreCase)) { webContext.Log.WriteError(Locale.IsRussian ? "Указан неверный защитный код, IP {0}" : "Invalid captcha specified, IP {0}", HttpContext.Connection.RemoteIpAddress); ModelState.AddModelError(string.Empty, dict.InvalidCaptcha); ModelState.Remove(nameof(CaptchaCode)); CaptchaCode = ""; } } }
protected void CreateUser_Click(object sender, EventArgs e) { bool isHuman = CaptchaCode.Validate(CaptchaCodeTextBox.Text); CaptchaCodeTextBox.Text = null; // clear previous user input if (isHuman) { var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>(); var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text }; IdentityResult result = manager.Create(user, Password.Text); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 string code = manager.GenerateEmailConfirmationToken(user.Id); string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request); manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>."); if (user.EmailConfirmed) { signInManager.SignIn(user, isPersistent: false, rememberBrowser: false); IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); } else { ErrorMessage.Text = "An email has been sent to your account. Please view the email and confirm your account to complete the registration process."; } } else { ErrorMessage.Text = result.Errors.FirstOrDefault(); } } else { ErrorMessage.Text = "The Captcha you entered is incorrect."; } }
/// <summary> /// 提交验证码 /// </summary> /// <param name="state"></param> private async Task SubmitCaptchaCodeAsync() { if (string.IsNullOrWhiteSpace(CaptchaCode)) { return; } OfoApi.CurUser.TelPhone = TelPhone; var verifyCode = await OfoApi.GetVerifyCodeAsync(CaptchaCode.Trim(), VerifyId); if (await CheckOfoApiResult(verifyCode)) { ContentPageArgs args = new ContentPageArgs() { Name = "登录第二步", HeaderVisibility = Visibility.Collapsed, ContentElement = new LoginSecondStepContentView(), }; ContentNavigation(args); } }