This project is an implementation of the ASP.NET Membership Provider using NHibernate and Sharp Architecture.
- 0.9.2
- Passwords are encrypted by default using a salt.
Create the entity responsible for persisting data between the Membership Provider and your database.
public class User : NHibernate.Sidekick.Security.MembershipProvider.Domain.UserBase { }
This model assumes your User
's Identifier is an integer. If this is not the case, inherit from UserBaseWithTypedId<TId>
instead.
This is who unobtrusively does all the work for you.
public class MembershipProvider : NHibernate.Sidekick.Security.MembershipProvider.Providers.MembershipProvider<User> { }
This model assumes your User
's Identifier is an integer. If this is not the case, inherit from MembershipProviderWithTypedId<T, TId>
instead.
public class AutoPersistenceModelGenerator : SharpArch.NHibernate.FluentNHibernate.IAutoPersistenceModelGenerator
{
public AutoPersistenceModel Generate()
{
AutoPersistenceModel mappings = AutoMap.AssemblyOf<User>(new AutomappingConfiguration());
// Default Sharp Architecture options go here.
mappings.IgnoreBase<UserBase>();
mappings.IgnoreBase(typeof(UserBaseWithTypedId<>));
}
}
This step is only relevant if you're using Fluent NHibernate's Automapping mechanism.
Set this within your application's web.config
:
<configuration>
<authentication mode="Forms">
<forms loginUrl="Account/LogOn" defaultUrl="/" />
</authentication>
</configuration>
Set this within your application's web.config
:
<configuration>
<system.web>
<membership defaultProvider="SidekickMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<add name="SidekickMembershipProvider"
applicationName="Sidekick_Security_SampleApp"
salt="SidekickSalt"
type="NHibernate.Sidekick.Security.Sampler.Domain.MembershipProvider"
enablePasswordRetrieval="true"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
passwordFormat="Clear"/>
</providers>
</membership>
</system.web>
</configuration>
@if (Request.IsAuthenticated) {
<text>Welcome <strong>@User.Identity.Name</strong>!</text>
}
[Authorize]
public class HomeController : Controller { }
If you're unfamiliar with ASP.NET's Membership Provider, you can find more information on Microsoft's MSDN and Patterns and Practices.
- .NET Framework 4.0
- System
- System.Core
- System.Data
- System.Configuration
- System.Web
- System.Web.ApplicationServices