Skip to content

robertwproxio/NHibernate-Sidekick-Membership-Provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NHibernate Sidekick's ASP.NET Membership Provider

This project is an implementation of the ASP.NET Membership Provider using NHibernate and Sharp Architecture.

Changelog

  • 0.9.2
  • Passwords are encrypted by default using a salt.

Implementation

1. Create your User entity

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.

2. Create your provider

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.

3. Ignore UserBase from Fluent NHibernate's Automap generator

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.

4. Set your application's authentication mode to Forms

Set this within your application's web.config:

<configuration>
	<authentication mode="Forms">
          <forms loginUrl="Account/LogOn" defaultUrl="/" />
	</authentication>
</configuration>

5. Set your provider's configuration options

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>

Simple usage

@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 Dependencies

  • .NET Framework 4.0
  • System
  • System.Core
  • System.Data
  • System.Configuration
  • System.Web
  • System.Web.ApplicationServices

Third-Party Dependencies

About

ASP.NET Membership Provider for Sharp Architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published