As promised, here's some preliminary documentation. I'll update this as I get feedback and make changes to the EntityMembershipProvider.
First, an overview. As I mentioned in my first post, I got tired of the limitiations I faced when working with the ASP.NET Membership controls. I loved that so much of the work was done for me, but it really felt like getting the Microsoft tables to work with my .netTiers tables required way too much effort. It was basically like working with two different types of data providers -- the Membership providers, and .netTiers. My goal with this project was to combine the two, so you can have all the advantages of the Membership controls (like the Login, LoginView, LoginName, and ChangePassword controls) without having to sacrafice the flexibility of using the .netTiers entites and web library.
Right now, there are some limitations built in to the EntityMembershipProvider:
1. It only supports entities generated from tables, not from views.
2. The primary key of your Users table must be either a UniqueIdentifier (a GUID) or an Int that auto-increments.
3. Table structure must have, at a minimum, the columns required by MembershipUser. More on this in a moment.
4. All extra columns must allow nulls.
5. Due to inheriting from the MembershipUser entity, Microsoft's built in ASP.NET Configuration Tool doesn't work. That sucks, but so far I have been unable to find a way around it.
But if you can live with that, the EntityMembershipProvider should work well.
To configure it, there are a few things that need to happen. First, you need to create a table that contains, at a minimum, the columns required by MembershipUser. To get a jump start, you can use this table:
CREATE TABLE Users
(
PKID INT IDENTITY(1,1) NOT NULL,
Username varchar(255) NOT NULL,
ApplicationName varchar(255) NOT NULL,
Email varchar(128) NOT NULL,
Comment varchar(255) NULL,
Password varchar(128) NOT NULL,
PasswordQuestion varchar(255) NULL,
PasswordAnswer varchar(255) NULL,
IsApproved bit NOT NULL DEFAULT(0),
LastActivityDate datetime NULL,
LastLoginDate datetime NULL,
LastPasswordChangedDate datetime NULL,
CreationDate datetime NOT NULL,
IsLockedOut bit NOT NULL DEFAULT(0),
LastLockoutDate datetime NULL,
FailedPasswordAttemptCount int NULL,
FailedPasswordAttemptWindowStart bit NOT NULL DEFAULT(0),
FailedPasswordAnswerAttemptCount int NULL,
FailedPasswordAnswerAttemptWindowStart datetime NULL
PRIMARY KEY (PKID)
)
You can add any number of columns you want to this table, as long as they allow null values.
Next, be sure that the SourceTables property includes the user table. Then set the EntityMembershipUserPKCol property to the primary key column on the Users table (in the table above, it's PKID). At this point, you're ready to generate. You should get an extra library, <RootNamespace>.Web.Security.
Finally, you must add a reference to the new library to your project and update your Web.config file to use the EntityMembershipProvider:
<system.web>
<membership defaultProvider="EntityMembershipProvider"
userIsOnlineTimeWindow="15">
<providers>
<add name="EntityMembershipProvider"
type="<RootNamespace>.Web.Security.EntityMembershipProvider"
enablePasswordRetrieval="true"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="15"
minRequiredPasswordLength="4"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression="" />
</providers>
</membership>
You can set the options listed here to the values required by your application.
And that's it! Your application should be running using the EntityMembershipProvider.
There's also an option to allow you to have column names that are different from the table defined above, but I'm gonna break that into its own post.