public ActionResult RegisterUser(LoginModel loginModel) { if (!ModelState.IsValid) { return(View(loginModel)); } var validationService = new PasswordValidationService(); if (loginModel.Password != loginModel.ConfirmPassword) { ModelState.AddModelError("Password", "As senhas não conferem"); return(View(loginModel)); } if (validationService.MeasurePasswordStrength(loginModel.Password) < 100) { ModelState.AddModelError("Password", "Senha não considerada forte. Por favor, coloque uma nova senha"); return(View(loginModel)); } loginModel.Password = _desEncryptor.Encrypt(loginModel.Password); loginModel.ConfirmPassword = _desEncryptor.Encrypt(loginModel.ConfirmPassword); _repository.Save(loginModel); return(RedirectToAction("Index", "Home")); }
public void WhenCryptAWordItMustBeDifferentBefore() { var word = "Murilo"; var encryptedWord = _desCrypt.Encrypt(word); Assert.AreNotEqual(word, encryptedWord); }
private void btnEncrypt_Click(object sender, EventArgs e) { if (this.comboBox1.SelectedIndex == 0) { string seckey = "tjlx4Xd_dXa6xsC3pq-uX92h"; DESEncryptor cryptor = new DESEncryptor(seckey); this.txtEncrypt.Text = cryptor.Encrypt(this.txtPlain.Text); } if (this.comboBox1.SelectedIndex == 1) { RSAEncryptor cryptor = new RSAEncryptor(null, null); this.txtEncrypt.Text = cryptor.Encrypt(this.txtPlain.Text); } if (this.comboBox1.SelectedIndex == 2) //HMACSHA256 { RSAEncryptor cryptor = new RSAEncryptor(null, null); this.txtEncrypt.Text = cryptor.Encrypt(this.txtPlain.Text); } else { string pwd = "800:6cc3cfc47dbd03c1cbc60398b0988a:186e5678c8b40921e56e847807b7de"; string[] arr = pwd.Split(':'); HMACSHA1Encryptor eb = new HMACSHA1Encryptor(arr[1], Convert.ToInt32(arr[0])); string arreer = eb.Encrypt("1"); } }
/// <summary> /// 记录用户登录信息 /// </summary> /// <param name="model">用户登录返回信息类</param> protected void RecordUserCookies(Model.User user) { var userMemberId = new HttpCookie("uid") { Value = DESEncryptor.Encrypt(user.UserId.ToString()), Domain = defaultDomain, Expires = DateTime.MinValue }; Response.Cookies.Add(userMemberId); }
/// <summary> /// 把用户信息存到cookie和session中 /// </summary> /// <param name="_customer"></param> /// <param name="_isPersistent"></param> /// <param name="_expiresTime"></param> private void passPort(Model.Customer _customer, bool _isPersistent, DateTime?_expiresTime) { System.Web.HttpContext context = System.Web.HttpContext.Current; context.Session[sessionKey] = _customer; HttpCookie newcookie = new HttpCookie(idCookieKey); newcookie.Value = DESEncryptor.Encrypt(_customer.CusId.ToString()); #if !DEBUG newcookie.Domain = defaultDomain; #endif context.Response.AppendCookie(newcookie); }
private void Login2(HttpContext context) { if ((RequestUsername != null && RequestUsername.Length > 0) && (RequestPWD != null && RequestPWD.Length > 0)) { int ret = 0; string url = string.Empty; //域账号 string username = RequestUsername.ToLower(); ret = BitAuto.YanFa.SysRightManager.Common.UserInfo.Login(username, DESEncryptor.Encrypt(RequestPWD)); if (ret > 0) { currentContext.Session["UserName"] = username; BitAuto.YanFa.SysRightManager.Common.UserInfo.passport(ret); string gourl = ConfigurationUtil.GetAppSettingValue("NotAccessMsgPagePath").Replace("~", "");//ConfigurationUtil.GetAppSettingValue("NotAccessMsgPagePath") if (!string.IsNullOrEmpty(RequestGoURL)) { gourl = RequestGoURL; } else { DataTable dtParent = BitAuto.YanFa.SysRightManager.Common.UserInfo.Instance.GetParentModuleInfoByUserID(Convert.ToInt32(currentContext.Session["userid"]), sysID); if (dtParent != null) { DataTable dtChild = BitAuto.YanFa.SysRightManager.Common.UserInfo.Instance.GetChildModuleByUserId(Convert.ToInt32(currentContext.Session["userid"]), sysID, dtParent.Rows[0]["moduleid"].ToString()); if (dtChild.Rows.Count > 0) { gourl = dtChild.Rows[0]["url"].ToString(); } } } ret = 1;//登陆成功 string content = string.Format("用户{1}(ID:{0})登录成功。", currentContext.Session["userid"], currentContext.Session["truename"]); BitAuto.YanFa.SysRightManager.Common.LogInfo.Instance.InsertLog(ConfigurationUtil.GetAppSettingValue("LoginLogModuleID"), (int)BitAuto.YanFa.SysRightManager.Common.LogInfo.ActionType.Login, content); url = gourl; } else if (ret == -1) { ret = -8; } else if (ret == -2) { ret = -7; } //int msg = Bll.UserInfo.Login(Page.Request.Form["username"].Trim(), Page.Request.Form["pwd"].Trim()); context.Response.Write(ret.ToString() + "," + url); context.Response.End(); return; } }
public void EncryptionRoundTrip() { string data = "Hello World!"; string plainTextData = string.Copy(data); string encryptedData; var encryptor = new DESEncryptor() { EncryptionKey = "12345678" }; encryptedData = encryptor.Encrypt(plainTextData); plainTextData = encryptor.Decrypt(encryptedData); Assert.AreEqual(data, plainTextData); Assert.AreNotEqual(data, encryptedData); }
public ActionResult BaseCallback(string code, string state) { Loger.Current.Write("OAuth2RedirectController.BaseCallback() begin code=" + code + ",state=" + state); if (!string.IsNullOrEmpty(code)) { var result = OAuth.GetAccessToken(appId, secret, code); if (result.errcode == ReturnCode.请求成功) { Loger.Current.Write("OAuth2RedirectController.BaseCallback() begin openid=" + result.openid); //openid存到cookie var sOpenId = new HttpCookie("openid") { //Value = DESEncryptor.Encrypt(result.openid), Value = result.openid, Domain = defaultDomain, Expires = DateTime.MinValue }; Response.Cookies.Add(sOpenId); // 根据OpenId找MemberId存到cookie var uid = Model.User.GetUserIdByOpenId(result.openid); if (uid > 0) { var userMemberId = new HttpCookie("uid") { Value = DESEncryptor.Encrypt(uid.ToString()), Domain = defaultDomain, Expires = DateTime.MinValue }; Response.Cookies.Add(userMemberId); } else { var httpCookie = Request.Cookies["uid"]; if (httpCookie != null) { httpCookie.Value = string.Empty; httpCookie.Expires = DateTime.Now.AddDays(-1); } } } } Loger.Current.Write("OAuth2RedirectController.BaseCallback() end"); return(Redirect(state)); }
private void UpdateUserPassword(HttpContext context) { string msg = VerifyData(); if (msg == string.Empty) { try { string oldPwd = DESEncryptor.Encrypt(RequestOldPWD); string pwd = DESEncryptor.Encrypt(RequestPWD); int ret = BitAuto.YanFa.SysRightManager.Common.UserInfo.Login(RequestUsername, oldPwd); if (ret > 0) { BitAuto.YanFa.SysRightManager.Common.UserInfo.Instance.UpdateUserPassword(ret, pwd); string content = string.Format("用户{1}(ID:{0})修改密码{2}为{3}成功。", ret, RequestUsername, oldPwd, pwd); BitAuto.YanFa.SysRightManager.Common.LogInfo.Instance.InsertLog(ConfigurationUtil.GetAppSettingValue("LoginLogModuleID"), (int)BitAuto.YanFa.SysRightManager.Common.LogInfo.ActionType.Update, content); msg = "success"; } else if (ret == -1) { msg = "原密码不正确"; } else if (ret == -2) { msg = "不存在此帐号"; } else if (ret == -3) { msg = "此帐号已停用"; } } catch (Exception ex) { msg = ex.Message; } } context.Response.Write(msg); context.Response.End(); }
/// <summary> /// 方法过滤器,在执行方法之前设置默认数据,视图直接调用 /// zhous,2014.02.22 /// </summary> /// <param name="filterContext">上下文</param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { ViewBag.WeiXinUrl = System.Configuration.ConfigurationManager.AppSettings["WeiXinUrl"]; ViewBag.AppVersion = System.Configuration.ConfigurationManager.AppSettings["AppVersion"]; ViewBag.ErrorMessage = "纳尼!出错啦?"; HttpContextBase httpContext = filterContext.HttpContext; if (httpContext == null) { throw new ArgumentNullException("httpContext"); } var IsVerificationOpenid = System.Configuration.ConfigurationManager.AppSettings["IsVerificationOpenid"].ToString(); if (IsVerificationOpenid == "true") { var openid = HttpContext.Request.Cookies["openid"]; if (openid == null || openid.Value == null) { httpContext.Response.Redirect(ViewBag.WeiXinUrl + "oauth2redirect/Index" + "?refUrl=" + httpContext.Server.UrlEncode(httpContext.Request.Url.ToString())); //阻止继续执行Action filterContext.Result = new HttpUnauthorizedResult(); return; } else { var uid = Model.User.GetUserIdByOpenId(openid.Value); if (uid > 0) { if (HttpContext.Request.Cookies["uid"] == null) { var userMemberId = new HttpCookie("uid") { Value = DESEncryptor.Encrypt(uid.ToString()), Domain = defaultDomain, Expires = DateTime.MinValue }; Response.Cookies.Add(userMemberId); } } else { var httpCookie = Request.Cookies["uid"]; if (httpCookie != null) { httpCookie.Value = string.Empty; httpCookie.Expires = DateTime.Now.AddDays(-1); } } } } else { var openid = HttpContext.Request.Cookies["openid"]; if (openid == null || openid.Value == null) { var sOpenId = new HttpCookie("openid") { Value = "octXZwokfgrCaMQncTpEmfm9gugA", Domain = defaultDomain, Expires = DateTime.MinValue }; Response.Cookies.Add(sOpenId); } openid = HttpContext.Request.Cookies["openid"]; var uid = Model.User.GetUserIdByOpenId(openid.Value); if (uid > 0) { var userMemberId = new HttpCookie("uid") { Value = DESEncryptor.Encrypt(uid.ToString()), Domain = defaultDomain, Expires = DateTime.MinValue }; Response.Cookies.Add(userMemberId); } } }
public void EncryptAttribute(XmlElement element, string name, string vale) { string data = DESEncryptor.Encrypt(vale); element.SetAttribute(name, data); }