Click here to Skip to main content
15,881,559 members
Articles / Web Development / ASP.NET

URL Object Serialization: An Effortless Approach to User Account Confirmation

Rate me:
Please Sign up or sign in to vote.
4.91/5 (42 votes)
25 Jan 2008LGPL38 min read 171.4K   569   89  
A URL Object Serialization component that provides compression and encryption of CLR objects, enabling embedding within URLs. Also includes a user account purging component that performs the periodic removal of unconfirmed user accounts, and a website that demonstrates the user account confirmation.
#region File and License Information
/*
<File>
	<Copyright>Copyright © 2007, Daniel Vaughan. All rights reserved.</Copyright>
	<License see="prj:///Documentation/License.txt"/>
	<Owner Name="Daniel Vaughan" Email="dbvaughan@gmail.com"/>
	<CreationDate>2008-01-18 21:09:17Z</CreationDate>
	<LastSubmissionDate>$Date: $</LastSubmissionDate>
	<Version>$Revision: $</Version>
</File>
*/
#endregion

using System;
using System.Configuration.Provider;
using System.Threading;
using System.Web.Security;

namespace Orpius.Web
{
	class AspNetMembershipUserPurger : ProviderBase, IUserPurger
	{
		static readonly object usersLock = new object();

		public void Purge(double olderThanMinutes)
		{
			if (olderThanMinutes < 0)
			{
				throw new ArgumentException("Value must be greater than 0", "olderThanMinutes");
			}

			if (!Monitor.TryEnter(usersLock))
			{
				return;
			}

			try
			{
				DateTime expireTime = DateTime.Now.AddMinutes(-olderThanMinutes);

				/* TODO: Change to a stored procedure. 
				 * This is very inefficient, 
				 * and is provided only for demonstration purposes. */
				MembershipUserCollection userCollection = Membership.GetAllUsers();
				foreach (MembershipUser user in userCollection)
				{
					if (!user.IsApproved && user.CreationDate < expireTime)
					{
						Membership.DeleteUser(user.UserName);
					}
				}
			}
			finally
			{
				Monitor.Exit(usersLock);
			}
		}
	}
}

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, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Engineer
Switzerland Switzerland
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.

Previously Daniel was a nine-time Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company.

Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.

Daniel is the developer behind several acclaimed mobile apps including Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably Codon.

Would you like Daniel to bring value to your organisation? Please contact

Blog | Twitter


Xamarin Experts
Windows 10 Experts

Comments and Discussions