Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • bsains 1 post 21 karma points
    Jan 21, 2010 @ 08:03
    bsains
    0

    Membership Provider AutoUnlock

    Looking for help with customisation of the default UmbracoMembershipProvider.

    Basically trying to overide the default ValidateUser method so that locked member accounts can be automatically unlocked after a predefined time limit.

    However it seems that the value for LastLockoutDate increments on each validation attempt. Despite the fact that the Unlock is called before the base ValidateUser method.

    Below is the code for the Validate user overide -

    public override bool ValidateUser(string username, string password)
            {

                MembershipUser mui = this.GetUser(username, false);

                if (mui.IsLockedOut && !AutoUnlockUser(mui))
                {
                    return false;
                }

                bool retval = base.ValidateUser(username, password);
              
                if (retval == false)
                {
                   return false;
                }
                else
                    return retval;  //first login was successful
                }
          
            }

     

    And code for AutoUnlockUser -

     

    protected virtual bool AutoUnlockUser(MembershipUser mui)
            {
                DateTime now = DateTime.UtcNow;

                if (EnableAutoUnlock && (mui != null) && (mui.IsLockedOut))
                {
                   
                    // if enough time has passed since the last lockout date, unlock the user
                  
                        if (mui.LastLockoutDate.ToUniversalTime().AddMinutes(AutoUnlockMinutes) <= now)
                        {
                            mui.UnlockUser();
                           Member m = Member.GetMemberFromLoginName(mui.UserName);
                           m.getProperty("locked").Value = "0";
                           m.getProperty("pwFails").Value = "0";
                           return true;
                        }
                        else
                        {
                            return false;
                        }             

                }          
                return false;
            }

     

  • Paul Blair 466 posts 731 karma points
    Jan 21, 2010 @ 19:54
    Paul Blair
    0

    Hi,

    This post will give you an idea on how to override the provider: http://www.nibble.be/?p=66

    Paul

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies