BlogEngine.Core.Providers.XmlMembershipProvider.ResetPassword C# (CSharp) Method

ResetPassword() public method

Resets a user's password to a new, automatically generated password.
public ResetPassword ( string username, string answer ) : string
username string The user to reset the password for.
answer string The password answer for the specified user.
return string
        public override string ResetPassword(string username, string answer)
        {
            var doc = new XmlDocument();
            doc.Load(XmlFullyQualifiedPath);
            var nodes = doc.GetElementsByTagName("User");
            var newPassword = Utils.RandomPassword();

            foreach (var node in
                nodes.Cast<XmlNode>().Where(
                    node =>
                    node["UserName"].InnerText.Equals(username, StringComparison.OrdinalIgnoreCase) &&
                    !string.IsNullOrEmpty(node["Password"].InnerText)))
            {
                string passwordPrep;
                if (this.passwordFormat == MembershipPasswordFormat.Hashed)
                {
                    passwordPrep = Utils.HashPassword(newPassword);
                }
                else
                {
                    passwordPrep = newPassword;
                }

                node["Password"].InnerText = passwordPrep;
                doc.Save(XmlFullyQualifiedPath);

                this.users = null;
                this.ReadMembershipDataStore();
                return newPassword;
            }

            return string.Empty;
        }