Felbook.Models.User.ChangePassword C# (CSharp) Method

ChangePassword() public method

Změnit heslo
public ChangePassword ( string value ) : void
value string heslo
return void
        public void ChangePassword(string value)
        {
            PasswordHash = CalculateHash(value);
        }

Usage Example

        public bool ChangePassword(string userName, string oldPassword, string newPassword)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("Value cannot be null or empty.", "userName");
            }
            if (String.IsNullOrEmpty(oldPassword))
            {
                throw new ArgumentException("Value cannot be null or empty.", "oldPassword");
            }
            if (String.IsNullOrEmpty(newPassword))
            {
                throw new ArgumentException("Value cannot be null or empty.", "newPassword");
            }

            try
            {
                User user = DBEntities.UserSet.Single(u => u.Username == userName);

                if (user.CheckPassword(oldPassword))
                {
                    user.ChangePassword(newPassword);
                    DBEntities.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (InvalidOperationException)
            {
                return(false);
            }
        }
All Usage Examples Of Felbook.Models.User::ChangePassword