Raju Fodse

Raju Fodse

  • 1.9k
  • 235
  • 21.9k

Require Case Sensitive Login page in MVC

Jul 10 2021 10:24 AM

Hi, I want to create Login page in mvc. in which login page ask for username and password which is store in database. I have created code for it which is work fine but 'Case Senstivity' Not wotk. Following is code for form login. How can I do for 'case Sensitivty' work

[AllowAnonymous]
[HttpPost]
public ActionResult Login(User model/*, string ReturnUrl = ""*/)
{
    using (LPDBContext context = new LPDBContext())
    {
        bool IsValidUser = context.Users.Any(user => user.Username.ToLower() ==
             model.Username.ToLower() && user.Password==model.Password);

        if (IsValidUser)
        {
            var objdata = context.Users.Where(a => a.Username.Equals(model.Username) && a.Password.Equals(model.Password)).FirstOrDefault();
            FormsAuthentication.SetAuthCookie(model.Username, false);
            Session["userimage"] = objdata.EmpNew.PhotoID;
            Session["userName"] = objdata.EmpNew.NickName;
            return RedirectToAction("Index", "Main");
        }
        ModelState.AddModelError("Username", "invalid Username or Password");
        return View();
    }

}

 


Answers (2)