Ejemplo n.º 1
0
        public ActionResult ChangePassword(string oldPassword, string newPassword, string repeatPassword)
        {
            string password = null;
            User tmp = SqlUser.GetUser(User.Identity.Name);
            password = SqlUser.GetUserPassword(tmp);

            if (Crypto.Hash(oldPassword) != password)
            {
                ViewBag.Message = "Stare hasło nie jest prawidłowe! ";
                return View();
            }
            else if(newPassword != repeatPassword)
            {
                ViewBag.Message = "Hasła nie są takie same! ";
                return View();

            }
            else if (newPassword == repeatPassword)
            {
                
                bool status = SqlUser.ChangePassword(Crypto.Hash(oldPassword), Crypto.Hash(newPassword), tmp.Email);
                return RedirectToAction("Logout");
            }
            else
            {
                ViewBag.Message = "Nie wiem jak to zrobiłeś/aś ale no nie pykło ";
                return View();
            }
           

        }
Ejemplo n.º 2
0
 /// <summary>
 /// Change Password
 /// </summary>
 /// <param name="currentPassword"></param>
 /// <param name="newPassword"></param>
 /// <returns></returns>
 public static ResponseOutput ChangePassword(string currentPassword, string newPassword)
 {
     var responseOutput = new ResponseOutput();
     responseOutput.IsSuccessful = false;
     if (string.IsNullOrWhiteSpace(newPassword))
     {
         responseOutput.TypeOfException = Enums.ExceptionType.Fault;
         responseOutput.OutputMessage = "New password is empty.";
         return responseOutput;
     }
     if (string.IsNullOrWhiteSpace(currentPassword))
     {
         responseOutput.TypeOfException = Enums.ExceptionType.Fault;
         responseOutput.OutputMessage = "Current password is empty.";
         return responseOutput;
     }
     if (UserContext.Current.User.IsAnonymous == true)
     {
         responseOutput.TypeOfException = Enums.ExceptionType.Fault;
         responseOutput.OutputMessage = "User is not logged in.";
         return responseOutput;
     }
     if (!string.IsNullOrWhiteSpace(currentPassword) && !string.IsNullOrWhiteSpace(newPassword) && UserContext.Current.User.IsAnonymous == false)
     {
         SqlUser sqlUser = new SqlUser();
         var userid = UserContext.Current.User.Id;
         var user = FindUser(userid);
         if (user != null)
         {
             if (user.Password == currentPassword)
             {
                 bool isChanged = sqlUser.ChangePassword(userid, currentPassword, newPassword);
                 responseOutput.IsSuccessful = isChanged;
                 if (!isChanged)
                 {
                     responseOutput.TypeOfException = Enums.ExceptionType.Fault;
                     responseOutput.OutputMessage = "Password has been not changed.";
                 }
                 else
                 {
                     responseOutput.TypeOfException = Enums.ExceptionType.NoException;
                     responseOutput.OutputMessage = "Your password has been successfully changed.";
                 }
             }
             else
             {
                 responseOutput.TypeOfException = Enums.ExceptionType.Fault;
                 responseOutput.OutputMessage = "Current Password is not matched.";
             }
         }
         else
         {
             responseOutput.TypeOfException = Enums.ExceptionType.Fault;
             responseOutput.OutputMessage = "User is not exist.";
         }
     }
     return responseOutput;
 }