public ActionResult LogOn(AccountModel accountModel)
        {
            var adm  = AccountDataMapper.GetAccountDataMapper();
            var user = adm.GetById(accountModel.Username.ToLower());

            if (user != null)
            {
                if (!user.Confirmed)
                {
                    ModelState.AddModelError("Username", "O username inserido ainda não foi confirmado. Por favor confirme através do seu email.");
                }
                else if (LoginUtils.ComparePasswords(accountModel.Password, user))
                {
                    FormsAuthentication.SetAuthCookie(user.Username, false);
                    return(RedirectToAction("Index", "Home", user));
                }
                /* Login Failed */
                else
                {
                    ModelState.AddModelError("Password", "A password inserida não é valida");
                }
            }
            else/*User not found. Please register*/
            {
                ModelState.AddModelError("Username", "O username inserido não corresponde a nenhum utilizador registado.");
            }
            return(View(accountModel));
        }
        public ActionResult ChangePassword(ChangePasswordModel changePasswordModel)
        {
            var user = User.Identity.Name;
            var adm  = AccountDataMapper.GetAccountDataMapper();
            var acc  = adm.GetById(user);

            if (ModelState.IsValid)
            {
                if (!LoginUtils.ComparePasswords(changePasswordModel.OldPw, acc))
                {
                    ModelState.AddModelError("OldPw", "Password incorrecta!");
                    return(View(changePasswordModel));
                }
                acc.Password = changePasswordModel.Pw1;
                LoginUtils.EncryptPassword(acc);
                return(View("PasswordChanged"));
            }
            return(View(changePasswordModel));
        }