/// <summary>
 /// Clears a lock so that the membership user can be validated.
 /// </summary>
 /// <param name="userName">The membership user to clear the lock status for.</param>
 /// <returns>
 /// true if the membership user was successfully unlocked; otherwise, false.
 /// </returns>
 public override bool UnlockUser(string userName)
 {
     try
     {
         User user = new User(userName);
         user.Disabled = false;
         user.Save();
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }
예제 #2
0
        private void CreateSection()
        {
            this.BulletedList1.Items.Add(new ListItem("Creating the section."));

            var sectionService = ApplicationContext.Services.SectionService;

            //Try & find a section with the alias of "nuget"
            var ecSection = sectionService.GetSections().SingleOrDefault(x => x.Alias == "eventCalendar");

            //If we can't find the section - doesn't exist
            if (ecSection == null)
            {
                //So let's create it the section
                sectionService.MakeNew("EventCalendar", "eventCalendar", "icon-calendar-alt");
                this.BulletedList1.Items.Add(new ListItem("Done creating the section."));

                //Add the section to the allowed once for the admin
                var admin = new User(0);
                if (!admin.Applications.Any(x => x.alias == "eventCalendar"))
                {
                    admin.AddApplication("eventCalendar");
                    admin.Save();
                }
                this.BulletedList1.Items.Add(new ListItem("Added Admin to the section."));
            }            
        }
        /// <summary>
        /// Processes a request to update the password for a membership user.
        /// </summary>
        /// <param name="username">The user to update the password for.</param>
        /// <param name="oldPassword">The current password for the specified user.</param>
        /// <param name="newPassword">The new password for the specified user.</param>
        /// <returns>
        /// true if the password was updated successfully; otherwise, false.
        /// </returns>
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            if (!User.validateCredentials(username, oldPassword))            
                return false;

            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, false);
            OnValidatingPassword(args);

            if (args.Cancel)
                if (args.FailureInformation != null)
                    throw args.FailureInformation;
                else
                    throw new MembershipPasswordException("Change password canceled due to new password validation failure.");

            User user = new User(username);
            string encodedPassword = EncodePassword(newPassword);            
            user.Password = encodedPassword;            
            user.Save();
            return (user.ValidatePassword(encodedPassword)) ? true : false;
        }
        /// <summary>
        /// Processes a request to update the password for a membership user.
        /// </summary>
        /// <param name="username">The user to update the password for.</param>
        /// <param name="oldPassword">The current password for the specified user.</param>
        /// <param name="newPassword">The new password for the specified user.</param>
        /// <returns>
        /// true if the password was updated successfully; otherwise, false.
        /// </returns>
        /// <remarks>
        /// During installation the application will not be configured, if this is the case and the 'default' password 
        /// is stored in the database then we will validate the user - this will allow for an admin password reset if required
        /// </remarks>
        protected override bool PerformChangePassword(string username, string oldPassword, string newPassword)
        {


            if (ApplicationContext.Current.IsConfigured == false && oldPassword == "default"
                || ValidateUser(username, oldPassword))
            {
                var args = new ValidatePasswordEventArgs(username, newPassword, false);
                OnValidatingPassword(args);

                if (args.Cancel)
                {
                    if (args.FailureInformation != null)
                        throw args.FailureInformation;
                    throw new MembershipPasswordException("Change password canceled due to password validation failure.");
                }

                var user = new User(username);
                //encrypt/hash the new one
                string salt;
                var encodedPassword = EncryptOrHashNewPassword(newPassword, out salt);

                //Yes, it's true, this actually makes a db call to set the password
                user.Password = FormatPasswordForStorage(encodedPassword, salt);
                //call this just for fun.
                user.Save();

                return true;    
            }

            return false;

        }