Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Custom Authentication provider by implementing IHttpModule, IPrincipal and IIdentity

, 2 Nov 2003
An article on writing Custom Authentication provider in ASP.NET
customauthentication_demo.zip
CustomAuthenticationDemo
bin
CustomAuthenticationDemo.csproj.webinfo
CustomAuthenticationDemo.vsdisco
Global.asax
_vti_cnf
_vti_pvt
_vti_script
_vti_txt
customauthentication_src.zip
CustomSecurity
bin
Debug
CustomSecurity.csproj.user
obj
Debug
temp
TempPE
using System;
using System.Security.Principal;

namespace CustomSecurity
{
	/// <summary>
	/// Represents the Identity of a User. 
	/// Stores the details of a User. 
	/// Implements the IIDentity interface.
	/// </summary>
	[Serializable]
	public class CustomIdentity : IIdentity
	{
		# region private variables
		
		private String userId;
		private int userPK;
		private bool login;
		private bool isSuperUser;
		private string fullName;
		private string userEmail;
		private string roles;

		#endregion

		# region constructors
		/// <summary>
		/// The default constructor initializes any fields to their default values.
		/// </summary>
		public CustomIdentity()
		{
			this.userPK			= 0;
			this.userId			= String.Empty;
			this.login			= false;
			this.isSuperUser	= false;
			this.fullName		= String.Empty;
			this.userEmail		= String.Empty;
			this.roles			= String.Empty;
		}

		/// <summary>
		/// Initializes a new instance of the CustomIdentity class 
		/// with the passed parameters
		/// </summary>
		/// <param name="uId">User ID of the user</param>
		/// <param name="upk">Primary Key of the User record in User table</param>
		/// <param name="islogin">Flag that indicates whether the user has been authenticated</param>
		/// <param name="isAdmin">Flag that indicates whether the user is an Administrator</param>
		/// <param name="userName">Full name of the User</param>
		/// <param name="email">Email of the User</param>
		public CustomIdentity(string uId, int upk, bool islogin, bool isAdmin, string userName, string email, string uRoles)
		{
			this.userPK			= upk;
			this.userId			= uId;
			this.login			= islogin;
			this.isSuperUser	= isAdmin;
			this.fullName		= userName;
			this.userEmail		= email;
			this.roles			= uRoles;
		}

		#endregion

		# region properties
		// Properties
		/// <summary>
		/// Gets the Authentication Type
		/// </summary>
		public string AuthenticationType 
		{
			get { return "Custom"; }
		}

		/// <summary>
		/// Indicates whether the User is authenticated
		/// </summary>
		public bool IsAuthenticated  
		{
			get { return login; }
			set { login = value; }
		}

		/// <summary>
		/// Gets or sets the UserID of the User
		/// </summary>
		public string Name 
		{
			get { return userId; }
			set { userId = value; }
		}

		/// <summary>
		/// Gets or sets the Primary Key for the User record
		/// </summary>
		public int UserPK 
		{
			get { return userPK; }
			set { userPK = value; }
		}

		/// <summary>
		/// Indicates whether the User is an Administrator
		/// </summary>
		public bool IsSuperUser
		{
			get { return isSuperUser; }
			set { isSuperUser = value; }
		}

		/// <summary>
		/// Gets or sets the Full Name of the User
		/// </summary>
		public string UserFullName
		{
			get { return fullName; }
			set { fullName = value; }
		}

		/// <summary>
		/// Gets or sets the Email of the User
		/// </summary>
		public string UserEmail
		{
			get { return userEmail; }
			set { userEmail = value; }
		}

		/// <summary>
		/// Gets or sets the Roles of the User
		/// The roles are stored in a pipe "|" separated string
		/// </summary>
		public string UserRoles
		{
			get { return roles; }
			set { roles = value; }
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

I Piscean
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 3 Nov 2003
Article Copyright 2003 by I Piscean
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid