/// <summary> /// Cookie验证 /// </summary> /// <param name="httpContext"></param> /// <returns></returns> public bool AuthenticationByCookie(HttpContextBase httpContext) { //检查Cookies["Employer"]是否存在 if (httpContext.Request.Cookies["Employer"] == null) { return(false); } //验证用户名密码是否正确 HttpCookie _cookie = httpContext.Request.Cookies["Employer"]; string _account = _cookie["EmployerAccount"]; string _password = _cookie["EmployerPwd"];//cookie里存的就是解密后的密码 if (_account == "" || _password == "") { return(false); } //Authentication是自己写的函数,验证账号密码是否正确 if (Employer.Authentication(_account, Common.Text.EnCrypt(_password))) { return(true); } else { return(false); } }
public ActionResult Index() { //检查Cookies["Employer"]是否存在 if (Request.Cookies["Employer"] != null) { //验证用户名密码是否正确 HttpCookie _cookie = Request.Cookies["Employer"]; string _account = _cookie["EmployerAccount"]; string _password = _cookie["EmployerPwd"];//cookie里原本存的就是加密后的密码 string _isDelete = _cookie["IsDelete"]; //Authentication是自己写的函数,验证账号密码是否正确 if (Employer.Authentication(_account, Server.UrlDecode(_password))) { if (_isDelete == "2") { ViewBag.AuthorityInfo = "<div class='alert alert-warning' style='margin-top:30px;'>等待审核,请您耐心等待,我们将在一个工作日之内审核完毕!(当前可查看注册信息和修改注册信息)</div>"; } else if (_isDelete == "0") { ViewBag.AuthorityInfo = "<div class='alert alert-success' style='margin-top:30px;'>已通过审核(可以添加文章,修改文章了)</div>"; } } } return(View()); }
public JsonResult CheckEmailUnique(string email) { var result = false; int count = 0; SqlConnection cnn = DBLink.GetConnection(); //string sqlstr = "Select Count(*) FROM Employer where Email='" + email + "' and IsDelete!=1"; string sqlstr = "Select Count(*) FROM Employer where Email='" + email + "'"; //检查Cookies["Employer"]是否存在(如果用户已经登陆可能是修改信息) if (Request.Cookies["Employer"] != null) { //用户已经登陆 //验证用户名密码是否正确 HttpCookie _cookie = Request.Cookies["Employer"]; string _account = _cookie["EmployerAccount"]; string _password = _cookie["EmployerPwd"];//cookie里存的先自己加密,再url加密的密码 string _isDelete = _cookie["IsDelete"]; //Authentication是自己写的函数,验证账号密码是否正确 if (Employer.Authentication(_account, Server.UrlDecode(_password))) { string url = HttpContext.Request.UrlReferrer.ToString(); int pos = url.LastIndexOf("/") + 1; string actionName = url.Substring(pos, url.Length - pos); //防止登陆用户再注册一个相同邮箱账号 if (actionName.ToLower() == "edit") { Employer employer = GetEmployerDetailsByAccount(_account); //防止修改信息时误判断邮箱已经存在 sqlstr += " and Email!='" + employer.Email + "'"; } } } SqlCommand cmm = new SqlCommand(sqlstr, cnn); cnn.Open(); count = int.Parse(cmm.ExecuteScalar().ToString()); cmm.Dispose(); cnn.Close(); result = (count == 0); return(Json(result, JsonRequestBehavior.AllowGet)); }