Exemplo n.º 1
0
        public bool ResetMyPassword(string emailAddress, IEmailProvider emailProvider)
        {
            var user = DataContext.UserIdentitySet.Where(h => h.EmailAddress == emailAddress).SingleOrDefault();

            var isReset           = false;
            var resetPassword     = "******";
            var encryptedPassword = Cipher.Encrypt(resetPassword);

            if (user == null)
            {
                throw new SecurityException("This email account " + emailAddress + " does not exist in our system.");
            }


            if (user.Deactivated != null || user.LockedOut != null)
            {
                throw new SecurityException("You account is not active, please contact the administrator.");
            }

            user.PasswordHash = encryptedPassword;

            emailProvider.SendPasswordResetEmail(user, resetPassword);

            DataContextSaveChanges();

            isReset = true;

            return(isReset);
        }