Are you sure you want to create your own Custom membership provider?

As you may have read in my previous posts I’ve been investigating the use of the ASP.NET membership provider with Silverlight. The next stage was to write my own custom membership provider because I’ve a requirement to have a two part user name, much like Domain\User Name rather than just User Name. The web has a number of tutorials about rolling your own provider but for me this seemed like over-kill, I’m quite happy with the SQL Provider I just want to enforce a few extra rules, store a couple of other facts, audit specific changes, etc. Although I could use a regular expression to help me out it wouldn’t fulfill all my requirements. So my solution is to just derive from the SQL Provider;
 

    public class MyOwnSqlProvider : SqlMembershipProvider          

    {

        public override bool ValidateUser(string username, string password)

        {

            System.Diagnostics.Debug.WriteLine(username + " – " + password);

            return base.ValidateUser(username, password);

        }

    }

 

There we have, I can intercept the calls, add my own rules, etc. The only other change is to the web config to tell the world about the new provider.

 

    <membership defaultProvider="MyAspNetSqlMembershipProvider">

      <providers>

        <add name="MyAspNetSqlMembershipProvider" type="MyMembershipDemo.Web.MyOwnSqlProvider" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>

      </providers>

 

I’m not suggesting that this removes the need to write your own provider but if, like me, you only want to make a couple of subtle changes then this might save a lot of effort. BTW if you do want to delve deeper into writing your provider then you should take a look at Microsoft’s Provider Toolkit

Advertisements
This entry was posted in Silverlight. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s