Ejemplo n.º 1
0
        /// <summary>
        /// 验证验证码
        /// </summary>
        /// <returns></returns>
        public string Verification()
        {
            GeetestLib geetest = new GeetestLib(publicKey, privateKey);
            Byte       gt_server_status_code = (Byte)Session[GeetestLib.gtServerStatusSessionKey];
            String     userID    = (String)Session["userID"];
            int        result    = 0;
            String     challenge = Request.Form.Get(GeetestLib.fnGeetestChallenge);
            String     validate  = Request.Form.Get(GeetestLib.fnGeetestValidate);
            String     seccode   = Request.Form.Get(GeetestLib.fnGeetestSeccode);

            if (gt_server_status_code == 1)
            {
                result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
            }
            else
            {
                result = geetest.failbackValidateRequest(challenge, validate, seccode);
            }
            if (result == 1)
            {
                return("ok");
            }
            else
            {
                return("sb");
            }
        }
Ejemplo n.º 2
0
        public static string GeetestCheck(string GeetestId, string geetest_challenge, string geetest_seccode, string geetest_validate)
        {
            string str = string.Empty;

            try
            {
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                string     GeetestPublicKey  = System.Configuration.ConfigurationManager.AppSettings["GeetestPublicKey"];
                string     GeetestPrivateKey = System.Configuration.ConfigurationManager.AppSettings["GeetestPrivateKey"];
                GeetestLib geetest           = new GeetestLib(GeetestPublicKey, GeetestPrivateKey);
                var        result            = geetest.enhencedValidateRequest(geetest_challenge, geetest_validate, geetest_seccode, GeetestId);

                if (result == 1)
                {
                    str = ResponseHelper.ResponseMsg("1", "极验证成功", "");
                }
                else
                {
                    str = ResponseHelper.ResponseMsg("-1", "极验证失败", "");
                }
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
Ejemplo n.º 3
0
        protected void submitBtn_Click(object sender, EventArgs e)
        {
            GeetestLib geetest = new GeetestLib(GeetestConfig.publicKey, GeetestConfig.privateKey);
            Byte       gt_server_status_code = (Byte)Session[GeetestLib.gtServerStatusSessionKey];
            String     userID    = (String)Session["userID"];
            int        result    = 0;
            String     challenge = Request.Form.Get(GeetestLib.fnGeetestChallenge);
            String     validate  = Request.Form.Get(GeetestLib.fnGeetestValidate);
            String     seccode   = Request.Form.Get(GeetestLib.fnGeetestSeccode);

            if (gt_server_status_code == 1)
            {
                result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
            }
            else
            {
                result = geetest.failbackValidateRequest(challenge, validate, seccode);
            }
            if (result == 1)
            {
                Response.Write("<div id='sb'>success</div>");
            }
            else
            {
                Response.Write(" ");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 验证验证码是否正确
        /// </summary>
        /// <returns></returns>
        public static bool Validate()
        {
            int result = 0;

            try
            {
                GeetestLib geetest = new GeetestLib(GeetestConfig.publicKey, GeetestConfig.privateKey);
                Byte       gt_server_status_code = (Byte)HttpContext.Current.Session[GeetestLib.gtServerStatusSessionKey];
                string     userID = (string)HttpContext.Current.Session["userID"];

                string challenge = HttpContext.Current.Request[GeetestLib.fnGeetestChallenge];
                string validate  = HttpContext.Current.Request[GeetestLib.fnGeetestValidate];
                string seccode   = HttpContext.Current.Request[GeetestLib.fnGeetestSeccode];
                if (gt_server_status_code == 1)
                {
                    result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
                }
                else
                {
                    result = geetest.failbackValidateRequest(challenge, validate, seccode);
                }
            }
            catch (Exception)
            {
            }
            return(result == 1);
        }
Ejemplo n.º 5
0
        public ApiResponse Success()
        {
            GeetestLib geetest = new GeetestLib(GeetestConfig.publicKey, GeetestConfig.privateKey);
            Byte       gt_server_status_code = (Byte)Context.Session[GeetestLib.gtServerStatusSessionKey];
            String     userID    = (String)Context.Session["sessionID"];
            int        result    = 0;
            String     challenge = Context.Request.Form.Get(GeetestLib.fnGeetestChallenge);
            String     validate  = Context.Request.Form.Get(GeetestLib.fnGeetestValidate);
            String     seccode   = Context.Request.Form.Get(GeetestLib.fnGeetestSeccode);

            if (gt_server_status_code == 1)
            {
                result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
            }
            else
            {
                result = geetest.failbackValidateRequest(challenge, validate, seccode);
            }
            if (result == 1)
            {
                return(ResponseHelper.CreateApiResponse(10000, "验证码校验成功"));
            }
            else
            {
                return(ResponseHelper.CreateApiResponse(10001, "验证码校验失败"));
            }
        }
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                GeetestLib geetest = new GeetestLib(_geetestOptions.Id, _geetestOptions.Key);
                //Byte gt_server_status_code = (Byte) Session[GeetestLib.gtServerStatusSessionKey];
                Byte   gt_server_status_code = 1;
                String userID         = "test";
                int    validateResult = 0;
                String challenge      = Request.Form[GeetestLib.fnGeetestChallenge];
                String validate       = Request.Form[GeetestLib.fnGeetestValidate];
                String seccode        = Request.Form[GeetestLib.fnGeetestSeccode];
                if (gt_server_status_code == 1)
                {
                    validateResult = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
                }
                else
                {
                    validateResult = geetest.failbackValidateRequest(challenge, validate, seccode);
                }
                if (validateResult != 1)
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View(model));
                }

                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    _logger.LogInformation(1, "User logged in.");
                    return(RedirectToLocal(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning(2, "User account locked out.");
                    return(View("Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View(model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        public void CheckCaptcha(string inputCaptcha)
        {
            var requestCookie = HttpContext.Current.Request.Cookies.Get("ClientToken");
            var clientToken   = "";

            if (requestCookie == null)
            {
                throw new UserFriendlyException("您的操作有误,请刷新重试");
            }
            clientToken = requestCookie.Value;
            var verifcationCache = _cacheManager.GetCache("ClientToken").GetOrDefault <string, VerifcationCache>(clientToken);

            switch (verifcationCache?.VerifcationType)
            {
            case VerifcationType.Image:
                if (string.IsNullOrEmpty(inputCaptcha))
                {
                    throw new UserFriendlyException("请输入验证码");
                }
                if (string.IsNullOrEmpty(verifcationCache?.Code))
                {
                    throw new UserFriendlyException("验证码已过期,请刷新重试");
                }
                if (inputCaptcha.ToLower().Trim() != verifcationCache?.Code?.ToLower())
                {
                    throw new UserFriendlyException("验证码输入错误");
                }
                _cacheManager.GetCache("ClientToken").Set(clientToken, "");
                break;

            case VerifcationType.Drag:
            case VerifcationType.Geetest:
                if (string.IsNullOrEmpty(inputCaptcha) ||
                    string.IsNullOrEmpty(verifcationCache?.Code) ||
                    inputCaptcha.ToLower().Trim() != verifcationCache?.Code?.ToLower())
                {
                    throw new UserFriendlyException("验证码验证失败");
                }
                break;

            case VerifcationType.GeetestNow:
                GeetestLib   geetest = GetGeetestLib();
                GeetestCheck input   = JsonConvert.DeserializeObject <GeetestCheck>(inputCaptcha);
                int          result  = geetest.enhencedValidateRequest(input.Challenge, input.Validate, input.Seccode);
                if (result != 1)
                {
                    throw new UserFriendlyException("验证失败");
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 验证是否正确
        /// </summary>
        /// <param name="publicKey">验证码ID</param>
        /// <param name="privateKey">验证码KEY</param>
        /// <param name="Challenge">参数一</param>
        /// <param name="Validate">参数二</param>
        /// <param name="Seccode">参数三</param>
        /// <returns></returns>
        public static bool Submit(string publicKey, string privateKey, string Challenge, string Validate, string Seccode)
        {
            GeetestLib geetest = new GeetestLib(publicKey, privateKey);
            string     gt_server_status_code = CookieHelper.Get(GeetestLib.gtServerStatusSessionKey);
            int        result = 0;

            if (gt_server_status_code == "1")
            {
                result = geetest.enhencedValidateRequest(Challenge, Validate, Seccode, "test");
            }
            else
            {
                result = geetest.failbackValidateRequest(Challenge, Validate, Seccode);
            }
            return(result == 1);
        }
Ejemplo n.º 9
0
        protected void submitBtn_Click(object sender, EventArgs e)
        {
            GeetestLib geetest = GeetestLib.getGtSession(Session);
            int        gt_server_status_code = GeetestLib.getGtServerStatusSession(Session);
            String     result = "";

            if (gt_server_status_code == 1)
            {
                result = geetest.enhencedValidateRequest(Request);
            }
            else
            {
                result = geetest.failbackValidateRequest(Request);
            }
            Response.Write(result);
        }
Ejemplo n.º 10
0
        public async Task <JsonResult> Login(LoginViewModel loginModel, string returnUrl = "", string returnUrlHash = "", string challenge = "", string validate = "", string seccode = "")
        {
            try
            {
                var geetest = new GeetestLib(
                    ConfigurationManager.AppSettings["CheckCode.GeetestLib.PublicKey"],
                    ConfigurationManager.AppSettings["CheckCode.GeetestLib.PrivateKey"]);
                var gtServerStatusCode = (Byte)Session[GeetestLib.gtServerStatusSessionKey];
                var userCheckCode      = (String)Session["userCheckCode"];
                var result             = gtServerStatusCode == 1 ? geetest.enhencedValidateRequest(challenge, validate, seccode, userCheckCode) : geetest.failbackValidateRequest(challenge, validate, seccode);
                if (result != 1)
                {
                    throw new UserFriendlyException("验证码错误!");
                }

                CheckModelState();

                var loginResult = await GetLoginResultAsync(
                    loginModel.UsernameOrEmailAddress,
                    loginModel.Password,
                    loginModel.TenancyName
                    );

                await SignInAsync(loginResult.User, loginResult.Identity, loginModel.RememberMe);

                if (string.IsNullOrWhiteSpace(returnUrl))
                {
                    returnUrl = Request.ApplicationPath;
                }

                if (!string.IsNullOrWhiteSpace(returnUrlHash))
                {
                    returnUrl = returnUrl + returnUrlHash;
                }
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message, ex.Details))));
            }

            return(Json(new AjaxResponse {
                TargetUrl = returnUrl
            }));
        }
Ejemplo n.º 11
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            string loginName  = StringHelper.SearchSafe(AdminName.Text);
            string loginEmial = StringHelper.SearchSafe(Email.Text);
            var    admin      = AdminBLL.Read(loginName);

            //如果账号不存在
            if (admin.Id <= 0)
            {
                ScriptHelper.AlertFront("账号不存在");
            }
            //如果账号不存在
            if (!string.Equals(admin.Email, loginEmial, StringComparison.OrdinalIgnoreCase))
            {
                ScriptHelper.AlertFront("账号、邮箱不匹配");
            }

            if (admin.Id > 0 && string.Equals(admin.Email, loginEmial, StringComparison.OrdinalIgnoreCase))
            {
                #region 滑块验证码
                GeetestLib geetest = new GeetestLib("b46d1900d0a894591916ea94ea91bd2c", "36fc3fe98530eea08dfc6ce76e3d24c4");
                Byte       gt_server_status_code = (Byte)Session[GeetestLib.gtServerStatusSessionKey];
                String     userID    = (String)Session["userID"];
                int        result    = 0;
                String     challenge = Request.Form.Get(GeetestLib.fnGeetestChallenge);
                String     validate  = Request.Form.Get(GeetestLib.fnGeetestValidate);
                String     seccode   = Request.Form.Get(GeetestLib.fnGeetestSeccode);
                try
                {
                    if (gt_server_status_code != null && gt_server_status_code == 1)
                    {
                        result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
                    }
                    else
                    {
                        result = geetest.failbackValidateRequest(challenge, validate, seccode);
                    }
                }
                catch (Exception ex)
                {
                    result = -1;//极验验证码出错,不进行验证
                }
                if (result == 1 || result == -1)
                {// 验证通过,发送邮件
                    string tempSafeCode = Guid.NewGuid().ToString();
                    AdminBLL.ChangeAdminSafeCode(admin.Id, tempSafeCode, RequestHelper.DateNow);
                    string              url             = "http://" + Request.ServerVariables["HTTP_HOST"] + "/Admin/ResetPassword.aspx?CheckCode=" + StringHelper.Encode(admin.Id + "|" + admin.Email + "|" + admin.Name + "|" + tempSafeCode, ShopConfig.ReadConfigInfo().SecureKey);
                    EmailContentInfo    emailContent    = EmailContentHelper.ReadSystemEmailContent("FindPassword");
                    EmailSendRecordInfo emailSendRecord = new EmailSendRecordInfo();
                    emailSendRecord.Title     = emailContent.EmailTitle;
                    emailSendRecord.Content   = emailContent.EmailContent.Replace("$Url$", url);
                    emailSendRecord.IsSystem  = (int)BoolType.True;
                    emailSendRecord.EmailList = admin.Email;
                    emailSendRecord.IsStatisticsOpendEmail = (int)BoolType.False;
                    emailSendRecord.SendStatus             = (int)SendStatus.No;
                    emailSendRecord.AddDate  = RequestHelper.DateNow;
                    emailSendRecord.SendDate = RequestHelper.DateNow;
                    emailSendRecord.ID       = EmailSendRecordBLL.AddEmailSendRecord(emailSendRecord);
                    EmailSendRecordBLL.SendEmail(emailSendRecord);
                    string emailResult = "您的申请已提交,请在15分钟内登录邮箱重设你的密码,!<a href=\"http://mail." + admin.Email.Substring(admin.Email.IndexOf("@") + 1) + "\"  target=\"_blank\">马上登录</a>";
                    ResponseHelper.Redirect("/admin/FindPassword.aspx?emailResult=" + Server.UrlEncode(emailResult));
                }
                else
                {
                    //验证失败
                    ScriptHelper.AlertFront("图片验证失败,请拖动图片滑块重新验证。");
                }
                #endregion
            }
        }
Ejemplo n.º 12
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            //如果账号不存在
            if (!string.Equals(NewPassword.Text, NewPassword2.Text, StringComparison.OrdinalIgnoreCase))
            {
                ScriptHelper.AlertFront("两次密码不一致");
            }
            else
            {
                #region 滑块验证码
                GeetestLib geetest = new GeetestLib("b46d1900d0a894591916ea94ea91bd2c", "36fc3fe98530eea08dfc6ce76e3d24c4");
                Byte       gt_server_status_code = (Byte)Session[GeetestLib.gtServerStatusSessionKey];
                String     userID    = (String)Session["userID"];
                int        result    = 0;
                String     challenge = Request.Form.Get(GeetestLib.fnGeetestChallenge);
                String     validate  = Request.Form.Get(GeetestLib.fnGeetestValidate);
                String     seccode   = Request.Form.Get(GeetestLib.fnGeetestSeccode);
                try
                {
                    if (gt_server_status_code != null && gt_server_status_code == 1)
                    {
                        result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
                    }
                    else
                    {
                        result = geetest.failbackValidateRequest(challenge, validate, seccode);
                    }
                }
                catch (Exception ex)
                {
                    result = -1;//极验验证码出错,不进行验证
                }
                if (result == 1 || result == -1)
                {// 验证通过,重置密码
                    string checkCode   = RequestHelper.GetForm <string>("CheckCode");
                    string decode      = StringHelper.Decode(checkCode, ShopConfig.ReadConfigInfo().SecureKey);
                    int    adminID     = Convert.ToInt32(decode.Split('|')[0]);
                    string newPassword = StringHelper.Password(NewPassword.Text, (PasswordType)ShopConfig.ReadConfigInfo().PasswordType);
                    // 重置密码
                    AdminBLL.ChangePassword(adminID, newPassword);
                    Task.Run(() => {
                        //安全码
                        ShopConfigInfo config = ShopConfig.ReadConfigInfo();
                        config.SecureKey      = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
                        ShopConfig.UpdateConfigInfo(config);
                    });
                    //清空safecode,finddate恢复
                    AdminBLL.ChangeAdminSafeCode(adminID, string.Empty, RequestHelper.DateNow);
                    //错误次数清零,解锁
                    AdminBLL.UpdateStatus(adminID);
                    string msg = "恭喜您,密码修改成功!" + "&nbsp;&nbsp;点击<a href=\"/admin/Login.aspx\" style=\"color: #1dd42b;font-size: larger;\">\"使用新密码登录\"</a>";
                    //清除原有的user Cookies
                    CookiesHelper.DeleteCookie(ShopConfig.ReadConfigInfo().AdminCookies);
                    CookiesHelper.DeleteCookie("AdminSign");

                    ResponseHelper.Redirect("/admin/ResetPassword.aspx?Result=" + Server.UrlEncode(msg));
                }
                else
                {
                    //验证失败
                    ScriptHelper.AlertFront("图片验证失败,请拖动图片滑块重新验证。");
                }
                #endregion
            }
        }
Ejemplo n.º 13
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            string loginName     = StringHelper.SearchSafe(AdminName.Text);
            string loginPass     = StringHelper.SearchSafe(Password.Text);
            var    theLoginAdmin = AdminBLL.Read(loginName);

            //如果登录日期与上次登录日期不是同一天,更新登录记录,清空错误次数,解除锁定
            if (theLoginAdmin.Id > 0 && (DateTime.Now - theLoginAdmin.LastLoginDate).Days > 0)
            {
                AdminBLL.UpdateLogin(theLoginAdmin.Id, RequestHelper.DateNow, ClientHelper.IP);
            }
            bool remember = Remember.Checked;

            loginPass = StringHelper.Password(loginPass, (PasswordType)ShopConfig.ReadConfigInfo().PasswordType);
            AdminInfo admin = AdminBLL.CheckLogin(loginName, loginPass);

            if (admin.Id > 0)
            {
                // 如果账户未锁定
                if (admin.Status == (int)BoolType.True)
                {
                    #region 滑块验证码
                    int result = 0;
                    try
                    {
                        GeetestLib geetest = new GeetestLib("b46d1900d0a894591916ea94ea91bd2c", "36fc3fe98530eea08dfc6ce76e3d24c4");
                        Byte       gt_server_status_code = (Byte)Session[GeetestLib.gtServerStatusSessionKey];
                        String     userID = (String)Session["userID"];

                        String challenge = Request.Form.Get(GeetestLib.fnGeetestChallenge);
                        String validate  = Request.Form.Get(GeetestLib.fnGeetestValidate);
                        String seccode   = Request.Form.Get(GeetestLib.fnGeetestSeccode);

                        if (gt_server_status_code != null && gt_server_status_code == 1)
                        {
                            result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
                        }
                        else
                        {
                            result = geetest.failbackValidateRequest(challenge, validate, seccode);
                        }
                    }
                    catch (Exception ex)
                    {
                        result = -1;    //极验验证码出错,不进行验证
                    }
                    if (result == 1 || result == -1)
                    {
                        #endregion

                        string randomNumber = Guid.NewGuid().ToString();
                        string sign         = FormsAuthentication.HashPasswordForStoringInConfigFile(admin.Id.ToString() + admin.Name + admin.GroupId.ToString() + randomNumber + ShopConfig.ReadConfigInfo().SecureKey + ClientHelper.Agent, "MD5");
                        string value        = sign + "|" + admin.Id.ToString() + "|" + admin.Name + "|" + admin.GroupId.ToString() + "|" + randomNumber;
                        if (remember)
                        {
                            CookiesHelper.AddCookie(ShopConfig.ReadConfigInfo().AdminCookies, value, 1, TimeType.Year);
                        }
                        else
                        {
                            CookiesHelper.AddCookie(ShopConfig.ReadConfigInfo().AdminCookies, value);
                        }
                        string signvalue = FormsAuthentication.HashPasswordForStoringInConfigFile(admin.Id.ToString() + admin.Name + admin.GroupId.ToString() + ShopConfig.ReadConfigInfo().SecureKey + ClientHelper.Agent + AdminBLL.Read(admin.Id).Password, "MD5");
                        CookiesHelper.AddCookie("AdminSign", signvalue);
                        AdminBLL.UpdateLogin(admin.Id, RequestHelper.DateNow, ClientHelper.IP);
                        AdminLogBLL.Add(ShopLanguage.ReadLanguage("LoginSystem"));
                        ResponseHelper.Redirect("/Admin");
                    }
                    else
                    {
                        //验证失败
                        string errorMsg = " *图片验证失败,请拖动图片滑块重新验证。";
                        ResponseHelper.Redirect("/Admin/login.aspx?errorMsg=" + errorMsg);
                    }
                }
                else
                {//如果账户已锁定
                    string errorMsg = " *温馨提示:您一天内登录错误达到3次,已被锁定,可联系网站客服解锁,也可次日重新登录。";
                    ResponseHelper.Redirect("/Admin/login.aspx?errorMsg=" + errorMsg);
                }
            }
            else
            {
                //登录失败,失败次数加1。如果失败超过3次,则锁定账户
                AdminBLL.UpdateLogin(loginName, RequestHelper.DateNow, ClientHelper.IP, 3);
                AdminLogBLL.Add("管理员:" + loginName + "在" + RequestHelper.DateNow + "登陆网站后台失败,登陆IP:" + ClientHelper.IP);
                if (theLoginAdmin.Id > 0 && theLoginAdmin.LoginErrorTimes >= 3)
                {
                    string errorMsg = " *温馨提示:您一天内登录错误达到3次,已被锁定,可联系网站客服解锁,也可次日重新登录。";
                    ResponseHelper.Redirect("/Admin/login.aspx?errorMsg=" + errorMsg);
                }
                else
                {
                    //ScriptHelper.AlertFront("登录失败", RequestHelper.RawUrl);
                    string errorMsg = " *用户名或密码错误,登录失败。";
                    ResponseHelper.Redirect("/Admin/login.aspx?errorMsg=" + Server.UrlEncode(errorMsg));
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 极验验证,1表示成功
        /// </summary>
        protected void GeetestValidate()
        {
            string loginName = StringHelper.SearchSafe(RequestHelper.GetForm <string>("AdminName"));
            string loginPass = StringHelper.SearchSafe(RequestHelper.GetForm <string>("Password"));

            #region 滑块验证码

            GeetestLib geetest = new GeetestLib("b46d1900d0a894591916ea94ea91bd2c", "36fc3fe98530eea08dfc6ce76e3d24c4");
            Byte       gt_server_status_code = (Byte)Session[GeetestLib.gtServerStatusSessionKey];
            String     userID    = (String)Session["userID"];
            int        result    = 0;
            String     challenge = Request.Form.Get(GeetestLib.fnGeetestChallenge);
            String     validate  = Request.Form.Get(GeetestLib.fnGeetestValidate);
            String     seccode   = Request.Form.Get(GeetestLib.fnGeetestSeccode);
            if (gt_server_status_code == 1)
            {
                result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
            }
            else
            {
                result = geetest.failbackValidateRequest(challenge, validate, seccode);
            }
            if (result != 1)
            {
                string errorMsg = " *验证失败,请重新验证。";
                Response.Clear();
                Response.Write(JsonConvert.SerializeObject(new { flag = "no", msg = errorMsg }));
                Response.End();
            }

            #endregion

            var theLoginAdmin = AdminBLL.Read(loginName);
            //如果登录日期与上次登录日期不是同一天,更新登录记录,清空错误次数,解除锁定
            if (theLoginAdmin.Id > 0 && (DateTime.Now - theLoginAdmin.LastLoginDate).Days > 0)
            {
                AdminBLL.UpdateLogin(theLoginAdmin.Id, RequestHelper.DateNow, ClientHelper.IP);
            }
            bool remember = Remember.Checked;
            loginPass = StringHelper.Password(loginPass, (PasswordType)ShopConfig.ReadConfigInfo().PasswordType);
            AdminInfo admin = AdminBLL.CheckLogin(loginName, loginPass);
            if (admin.Id > 0)
            {
                // 如果账户未锁定
                if (admin.Status == (int)BoolType.True)
                {
                    string randomNumber = Guid.NewGuid().ToString();
                    string sign         = FormsAuthentication.HashPasswordForStoringInConfigFile(admin.Id.ToString() + admin.Name + admin.GroupId.ToString() + randomNumber + ShopConfig.ReadConfigInfo().SecureKey + ClientHelper.Agent, "MD5");
                    string value        = sign + "|" + admin.Id.ToString() + "|" + admin.Name + "|" + admin.GroupId.ToString() + "|" + randomNumber;
                    if (remember)
                    {
                        CookiesHelper.AddCookie(ShopConfig.ReadConfigInfo().AdminCookies, value, 1, TimeType.Year);
                    }
                    else
                    {
                        CookiesHelper.AddCookie(ShopConfig.ReadConfigInfo().AdminCookies, value);
                    }
                    string signvalue = FormsAuthentication.HashPasswordForStoringInConfigFile(admin.Id.ToString() + admin.Name + admin.GroupId.ToString() + ShopConfig.ReadConfigInfo().SecureKey + ClientHelper.Agent + AdminBLL.Read(admin.Id).Password, "MD5");
                    CookiesHelper.AddCookie("AdminSign", signvalue);
                    AdminBLL.UpdateLogin(admin.Id, RequestHelper.DateNow, ClientHelper.IP);
                    AdminLogBLL.Add(ShopLanguage.ReadLanguage("LoginSystem"));
                    //ResponseHelper.Redirect("/Admin");
                    Response.Clear();
                    Response.Write(JsonConvert.SerializeObject(new { flag = "ok", msg = "" }));
                    Response.End();
                }
                else
                {//如果账户已锁定
                    string errorMsg = " *温馨提示:您一天内登录错误达到5次,已被锁定,可联系网站客服解锁,也可次日重新登录。";
                    //ResponseHelper.Redirect("/Admin/login.aspx?errorMsg=" + errorMsg);
                    Response.Clear();
                    Response.Write(JsonConvert.SerializeObject(new { flag = "no", msg = errorMsg }));
                    Response.End();
                }
            }
            else
            {
                //登录失败,失败次数加1。如果失败超过5次,则锁定账户
                AdminBLL.UpdateLogin(loginName, RequestHelper.DateNow, ClientHelper.IP, 5);

                if (theLoginAdmin.Id > 0 && theLoginAdmin.LoginErrorTimes >= 5)
                {
                    string errorMsg = " *温馨提示:您一天内登录错误达到5次,已被锁定,可联系网站客服解锁,也可次日重新登录。";
                    //ResponseHelper.Redirect("/Admin/login.aspx?errorMsg=" + errorMsg);
                    Response.Clear();
                    Response.Write(JsonConvert.SerializeObject(new { flag = "no", msg = errorMsg }));
                    Response.End();
                }
                else
                {
                    string errorMsg = " *用户名或密码错误,登录失败。";
                    //ResponseHelper.Redirect("/Admin/login.aspx?errorMsg=" + errorMsg);
                    Response.Clear();
                    Response.Write(JsonConvert.SerializeObject(new { flag = "no", msg = errorMsg }));
                    Response.End();
                }
            }
        }
Ejemplo n.º 15
0
    protected void btnDL_Click(object sender, EventArgs e)
    {
        if (txtZH.Text.ToString() == "" || pwd.Text.ToString() == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "status", "alert('输入不能为空');", true);
            return;
        }

        GeetestLib geetest = new GeetestLib(GeetestConfig.publicKey, GeetestConfig.privateKey);
        Byte       gt_server_status_code = (Byte)Session[GeetestLib.gtServerStatusSessionKey];
        String     userID    = (String)Session["userID"];
        int        result    = 0;
        String     challenge = Request.Form.Get(GeetestLib.fnGeetestChallenge);
        String     validate  = Request.Form.Get(GeetestLib.fnGeetestValidate);
        String     seccode   = Request.Form.Get(GeetestLib.fnGeetestSeccode);

        if (gt_server_status_code == 1)
        {
            result = geetest.enhencedValidateRequest(challenge, validate, seccode, userID);
        }
        else
        {
            result = geetest.failbackValidateRequest(challenge, validate, seccode);
        }
        SqlParameter[] paras =
        {
            new SqlParameter("@name", txtZH.Text.ToString().Trim()),
            new SqlParameter("@pwd",  System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd.Text.Trim(), "MD5").ToLower())
        };
        if (result != 1)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "one", "alert('请输入验证码!');", true);
            return;
        }

        SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.GetConnSting(DB_JOB), CommandType.Text, "select u_id,u_name,u_type,thisIP,thisTime from web_usr where u_name=@name and u_pwd=@pwd", paras);

        if (sdr.HasRows)
        {
            if (sdr.Read())
            {
                Session["userId"]    = sdr["u_id"].ToString();
                Session["loginName"] = sdr["u_name"].ToString();
                Session["uType"]     = sdr["u_type"].ToString();
                SqlParameter[] tparas =
                {
                    new SqlParameter("@id",  sdr["u_id"].ToString()),
                    new SqlParameter("@lip", sdr["thisIP"].ToString()),
                    new SqlParameter("@lt",  sdr["thisTime"].ToString()),
                    new SqlParameter("@tip", IPAddress),
                    //new SqlParameter("@tt",DateTime.Now.ToString())
                };
                SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(DB_JOB), CommandType.Text, "update web_usr set lastIP=@lip,lastTime=@lt,thisIP=@tip,thistime='" + DateTime.Now.ToString() + "' where u_id=@id", tparas);
                Response.Redirect("../admin/index.aspx");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "one", "alert('帐号或者密码错误,晴重新输入!');", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "one", "alert('帐号或者密码错误,晴重新输入!');", true);
        }
    }