示例#1
0
 //验证账号密码是否正确
 public UserLoginModel Login(string userName, string passWord)
 {
     UserLoginModel userModel = new UserLoginModel();
     //if (userName.Contains("@"))
     //{
     //    var user = _db.Users.SingleOrDefault(a => a.UserName == userName & a.PassWord == passWord);
     //    if (user == null)
     //    {
     //        return userModel;
     //    }
     //    userModel.UserName = user.UserName;
     //    userModel.PassWord = user.PassWord;
     //    userModel.IsUser = false;
     //}
     //else
     //{
     string pwSalt = "B2wckID6gEOoK4ae0aqbzXRWMpjIlj88WQmMxAaM1P0";
     var hash_pw = FormsAuthentication.HashPasswordForStoringInConfigFile(pwSalt + passWord, "SHA1");
     var user = _db.Users.SingleOrDefault(a => a.UserName == userName & a.PassWord == hash_pw);
     if (user == null)
     {
         return userModel;
     }
     userModel.UserName = user.UserName;
     userModel.PassWord = user.PassWord;
     //userModel.IsUser = true;
     //}
     return userModel;
 }
示例#2
0
 public ActionResult PstLogin(UserLoginModel userLoginModel, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         var user = lamponSv.Login(userLoginModel.UserName, userLoginModel.PassWord);
         if (!String.IsNullOrEmpty(user.UserName))
         {
             Session["CurrentUser"] = user;
             //FormsAuthentication.SetAuthCookie(user.UserName, false);
             //if (user.IsUser)
             //{
             return Json(new { res = "ok", url = Url.Action("Main", "Lampon") });
             //}
             //else
             //{
             //    return Json(new { res = "ok", url = Url.Action("Index", "Lampon") });
             //}
             //if (String.IsNullOrEmpty(returnUrl))
             //{
             //    return Json(new { res = "ok", url = Url.Action("Main", "Lampon") });
             //}
             //else
             //{
             //    return Json(new { res = "ok", url = returnUrl });
             //}
         }
         return Json(new { res = "fail", msg = "您输入的账号或者密码错误" });
     }
     return Json(new { res = "fail", msg = "登录失败" });
 }