记住我WebSecurity.Login

时间:2013-11-13 11:31:46

标签: remember-me

我正在开发一个MVC4中的Web应用程序,并且登录视图有选项记住我 - 实现此功能我正在使用由 -

创建的cookie
WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)

登录方法如下

   [AllowAnonymous]
   public ActionResult Login()
   {       //Get persistant cookie
     HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; 
     if (!ReferenceEquals(authCookie, null))
     {      //Decrypt
         FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); 
          string userName = Server.HtmlEncode(ticket.Name); //GetuserName
          // get Role and redirect in  as done after authentication
               return RedirectToDefaultView(returnUrl, userName); 
      }
            return View();
}

我有一些担忧 - 如果这是最佳做法,因为我只是验证Cookie,如果它存在于客户端计算机上,我调用方法RedirectToDefaultView(returnUrl,userName),它在WebSecurity.Login(模型之后)调用。 UserName,model.Password,persistCookie:model.RememberMe)in 以下方法..

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{ 
    if(WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
          return RedirectToDefaultView(returnUrl, userName); 
}

我出于某种原因无法在登录控制中保留密码后选择的方法,并且还在网站上阅读这不是一个好习惯。

@Html.PasswordFor(model => model.Password, new { @class = "password-icon", @maxlength = 30 })

对此有任何建议或帮助都是帮助。

由于 HSR。

0 个答案:

没有答案
相关问题