Exemplo n.º 1
0
        //Logs in user based on Username and Password and then redirects them to their Profile Page. If they enter incorrectly it will keep them at the loginpage.
        public ActionResult LoginUser(string username, string pass)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    MongoCRUD db = new MongoCRUD("BZBugs");
                    List<LoginModel> user = db.FindLoginRecordByUsername<LoginModel>(username);

                    bool isPasswordMatched = VerifyPassword(pass, user.First().Salt, user.First().Hash);
                    if (isPasswordMatched)
                    {
                        //Login Successfull           
                        LoginModel model = db.FindLoginRecord<LoginModel>(username, user.First().Salt, user.First().Hash);                       
                        return View("~/Views/Home/Profile.cshtml", model);
                    }
                    else
                    {
                        //Login Failed
                        ModelState.AddModelError("", "The password is incorrect.");
                        return View("LoginPage");
                    }
                }
                else
                {
                    //Login Failed
                    ModelState.AddModelError("", "The Username or Password is incorrect.");
                    return View("LoginPage");
                }
            }
            catch
            {
                //Login Failed
                ModelState.AddModelError("", "The Username or Password is incorrect.");
                return View("LoginPage");
            }   
        }