コード例 #1
0
        public IActionResult Login(UserAccount ua)
        {
            if (ModelState.IsValid)
            {
                if (_service.Contains(ua))
                {
                    //check password
                    if (_service.Get(ua.UserName).Password == ua.Password)
                    {
                        HttpContext.Session.SetString("username", ua.UserName);
                    }
                    ModelState.AddModelError("Password", "Incorrect password");
                }
                else
                {
                    ModelState.AddModelError("UserName", "Username does not exist");
                }
            }


            return(View());
        }