<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tayyab Bin Tariq &#187; Web Development</title>
	<atom:link href="http://tayyab.xenoglaux-solutions.com/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://tayyab.xenoglaux-solutions.com</link>
	<description>I like sharing what i know</description>
	<lastBuildDate>Fri, 21 May 2010 20:59:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Writing Unified Scalable Application Logic: Windows Workflow Foundation</title>
		<link>http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/</link>
		<comments>http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/#comments</comments>
		<pubDate>Sat, 23 May 2009 19:55:31 +0000</pubDate>
		<dc:creator>tayyabtariq</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Workflow Foundation]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Scalable Application Logic]]></category>
		<category><![CDATA[Scalable Applications]]></category>
		<category><![CDATA[Unified Application Logic]]></category>
		<category><![CDATA[Unified Logic]]></category>
		<category><![CDATA[Unified Scalable]]></category>
		<category><![CDATA[Visual Studio.NET]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Windows Workflow Foundation]]></category>

		<guid isPermaLink="false">http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/</guid>
		<description><![CDATA[Everyone who writes applications or creates software wants to create scalable and easy to understand solutions. The problem however is that simple software is not scalable and scalable applications can get too hard to understand because of their distributed logic development. 
 
A simple application may be implemented as shown in the following figure.
 
Figure [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone who writes applications or creates software wants to create scalable and easy to understand solutions. The problem however is that simple software is not scalable and scalable applications can get too hard to understand because of their distributed logic development. </p>
<p> <span id="more-99"></span>
<p>A simple application may be implemented as shown in the following figure.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image3.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="363" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb3.png" width="644" border="0" /></a> </p>
<p><strong>Figure 1: Simple unified logic that runs in a single process and thread (Courtesy MSDN).</strong></p>
<p>The above pseudo-code takes input from the client and based on the input executed different paths. Note that the input is taken at different points in the code. The state of the application/process is represented here by a simple string. Although this application development style is simple and easy to understand, it is not scalable. Imagine you are using such application logic for a hiring process where the inputs can come after days and even weeks. Your server would have to keep the process alive and running for this whole period. Imagine how much resources it would take to cater for thousands of users. What if the server fails during this period?</p>
<p>Considering these problems, lets look at another solution. This time round we separate the application logic at the freezing points (the input). Breaking the application logic allows the application to run as two different threads. This can solve a few of the problems described above.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image4.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="368" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb4.png" width="644" border="0" /></a> </p>
<p><strong>Figure 2: Breaking the application logic (Courtesy MSDN).</strong></p>
<p>Note that this time round the state is stored outside of the process in a database. The reason is that whenever the second process starts it needs to get the current state from some “persistent” store. Also note that the two application parts can now run on two different machines. Can you see a problem with this? The problem comes from the fact that it is hard for the second process to know whether the if was executed in the first part or the else (of course you would have to make this a part of the state). The point here is that the state becomes complex and we have to introduce a number of checks in the second part of the application. </p>
<p>The first figure is how our usual desktop applications run. they have their state stored in some memory variables that vanish as soon as the application ends. The applications which remember what you did last time have to save this state in some persistent storage. The second example is how ASP.NET applications work. The application logic is implemented in a distributed manner (on different pages). This not only makes it difficult for people to understand the process but also the programmer has to perform a series of checks whenever a page loads. It is also to be noted that the first type provides us unified logic whereas the second provides us scalability. </p>
<h2>The Solution</h2>
<p>Using windows workflows can help us solve these problems. WF function just as a normal program providing mechanism for input, output, control flow etc. However, all these are done with the help of activities, see diagram below.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image5.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb5.png" width="552" border="0" /></a> </p>
<p><strong>Figure 3: In a workflow all the things are done with the help of activities (Courtesy MSDN)</strong></p>
<p>As you can probably already see that unified logic is provided by workflows, let us see how WF solve the problem of scalability. All the work in the WF is done using activates, and as seen the WF provides all the elements of a usual programming language. The difference however is that all these activities are classes themselves, and they are executed on a WF Runtime which knows how to run these classes (activities).</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image6.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb6.png" width="545" border="0" /></a> </p>
<p><strong>Figure 3: WF Runtime executes activities in order (Courtesy MSDN).</strong></p>
<p>When it begins the workflow runtime executes the outer most activity first, which in this case is a sequential workflow. Then it executes the activities one after the other in order determined by the workflow. One thing to note here is that the activities are objects, and therefore can be described in any language, making the workflow independent of the language. Also that the WF Runtime does not know anything about the internals of the activity it is executing, allow the programmer to fill in what is to be done. WF provides a Base Activity Library (BAL) from which you can pick activities to include in your workflow. You can also create activates of your own, called custom activities. </p>
<p>The big question arises, why go through all this pain? The first answer to this question has already been answered, it provides unified logic. However, to be scalable the server application cannot be stuck with one process. One solution to this is the ASP.NET way, i.a. to break the application logic down into small chunks, however this is something we are trying to avoid. Moreover, the programmer than has to explicitly deal with state. As you can probably notice this WF is already broken down into chunks, this allows the WF to persist (not block waiting for an event). When at the start of our example workflow, the workflow is waiting for input the WF Runtime realizes this and stores the state of the WF in a persistent storage (we say the WF persists). This allows for the server resources to be used elsewhere. When the input arrives the WF Runtime wakes up the WF.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image7.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="452" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb7.png" width="644" border="0" /></a> <strong>Figure 5: The workflow can persist (Courtesy MSDN).</strong></p>
<p>Another advantage of the workflow being broken down from the perspective of scalability is the ability of the WF to be run on different machines when it resumes, as shown in the following diagram.</p>
<p>&#160;<a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image8.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="434" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb8.png" width="644" border="0" /></a> </p>
<p><strong>Figure 6 Different parts of a workflow can run on different machines</strong></p>
<h3>Other Benefits</h3>
<p>Other benefits of using windows workflows include the following</p>
<h4>Coordinating Parallel Work</h4>
<p>The WF allows you to coordinate parallel work in a better way by using the parallel activity which is part of BAL (More on this in later articles).</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image9.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="482" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb9.png" width="644" border="0" /></a> </p>
<p><strong>Figure 7 Workflows can run parallel activates (Courtesy MSDN).</strong></p>
<h4>Providing Tracking</h4>
<p>Tracking processes is an important part of any business application. WF makes it extremely easy to do this by providing tracking services. The tracking services are extremely closely linked to persistence (state maintenance) because the state of the WF has all the information one needs for tracking a WF.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image10.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb10.png" width="577" border="0" /></a>&#160; </p>
<p><strong>Figure 8 You can track the WF using tracking services (Courtesy MSDN).</strong></p>
<h4>Creating custom activities</h4>
<p>WF allows you to create custom activities that you can re use as is suited to your business application, allowing to use OO concepts in WF.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image11.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb11.png" width="250" border="0" /></a> </p>
<p><strong>Figure 9 You can create custom activities (Courtesy MSDN).</strong></p>
<h4>Fully Declarative Language</h4>
<p>WFs are fully declarative as each workflow is represented by a corresponding XAML file.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image12.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="475" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb12.png" width="582" border="0" /></a> </p>
<p><strong>Figure 10 WFs are fully declarative (Courtesy MSDN).</strong></p>
<p>&#160;</p>
<h4>Related articles</h4>
<p><a title="http://msdn.microsoft.com/en-us/library/dd851337.aspx" href="http://msdn.microsoft.com/en-us/library/dd851337.aspx">http://msdn.microsoft.com/en-us/library/dd851337.aspx</a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/" target="_blank"><img src="http://tayyab.xenoglaux-solutions.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Form Based Authentication in ASP.NET</title>
		<link>http://tayyab.xenoglaux-solutions.com/2009/04/30/form-based-authentication-in-aspnet/</link>
		<comments>http://tayyab.xenoglaux-solutions.com/2009/04/30/form-based-authentication-in-aspnet/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 11:39:07 +0000</pubDate>
		<dc:creator>tayyabtariq</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Form Based Authentication]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[login security]]></category>
		<category><![CDATA[Visual Studio.NET]]></category>

		<guid isPermaLink="false">http://tayyab.xenoglaux-solutions.com/2009/04/30/form-based-authentication-in-aspnet/</guid>
		<description><![CDATA[This article demonstrates how to implement forms-based authentication by using a database to store the users.
 
Create an ASP.NET Application Using C# .NET

Open Visual Studio .NET. 
Create a new ASP.NET Web application, and specify the name and location.

Configure the Security Settings in the Web.config File
 This section demonstrates how to add and modify the &#60;authentication&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>This article demonstrates how to implement forms-based authentication by using a database to store the users.</p>
<p> <span id="more-58"></span><br />
<h2>Create an ASP.NET Application Using C# .NET</h2>
<ol>
<li>Open Visual Studio .NET. </li>
<li>Create a new ASP.NET Web application, and specify the name and location.</li>
</ol>
<h2>Configure the Security Settings in the Web.config File</h2>
<p> This section demonstrates how to add and modify the <b>&lt;authentication&gt;</b> and <b>&lt;authorization&gt;</b> configuration sections to configure the ASP.NET application to use forms-based authentication.
<ol>
<li>In Solution Explorer, open the Web.config file. </li>
<li>Change the authentication mode to <b>Forms</b>. </li>
<li>Insert the &lt;Forms&gt; tag, and fill the appropriate attributes. Copy the following code, and then click <strong>Paste as HTML</strong> on the <strong>Edit</strong> menu to paste the code in the <b>&lt;authentication&gt;</b> section of the file:</li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">authentication</span> <span style="color: #ff0000">mode</span><span style="color: #0000ff">=&quot;Forms&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">forms</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;.ASPXFORMSDEMO&quot;</span> <span style="color: #ff0000">loginUrl</span><span style="color: #0000ff">=&quot;logon.aspx&quot;</span> </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060">   3:</span>    <span style="color: #ff0000">protection</span><span style="color: #0000ff">=&quot;All&quot;</span> <span style="color: #ff0000">path</span><span style="color: #0000ff">=&quot;/&quot;</span> <span style="color: #ff0000">timeout</span><span style="color: #0000ff">=&quot;30&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060">   4:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">authentication</span><span style="color: #0000ff">&gt;</span> </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060">   5:</span>     </pre>
<p><!--CRLF--></div>
</p></div>
<li>Deny access to the anonymous user in the <b>&lt;authorization&gt;</b> section as follows:</li>
</ol>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">authorization</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">deny</span> <span style="color: #ff0000">users</span> <span style="color: #0000ff">=&quot;?&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060">   3:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">allow</span> <span style="color: #ff0000">users</span> = <span style="color: #0000ff">&quot;*&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060">   4:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">authorization</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></div>
</div>
<h2>Create a Logon.aspx Page</h2>
<ol>
<li>Add a new Web Form to the project named Logon.aspx. </li>
<li>Open the Logon.aspx page in the editor, and switch to HTML view. </li>
<li>Copy the following code, and use the <strong>Paste as HTML</strong> option on the <strong>Edit</strong> menu to insert the code between the &lt;form&gt; tags: </li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">h3</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">font</span> <span style="color: #ff0000">face</span><span style="color: #0000ff">=&quot;Verdana&quot;</span><span style="color: #0000ff">&gt;</span>Logon Page<span style="color: #0000ff">&lt;/</span><span style="color: #800000">font</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">h3</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060">   4:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">table</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060">   5:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">tr</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum6" style="color: #606060">   6:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span>Email:<span style="color: #0000ff">&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum7" style="color: #606060">   7:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">input</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">=&quot;txtUserName&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;text&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum8" style="color: #606060">   8:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">ASP:RequiredFieldValidator</span> <span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">=&quot;txtUserName&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum9" style="color: #606060">   9:</span>            <span style="color: #ff0000">Display</span><span style="color: #0000ff">=&quot;Static&quot;</span> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">=&quot;*&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum10" style="color: #606060">  10:</span>            <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;vUserName&quot;</span> <span style="color: #0000ff">/&gt;&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum11" style="color: #606060">  11:</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">tr</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum12" style="color: #606060">  12:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">tr</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum13" style="color: #606060">  13:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span>Password:<span style="color: #0000ff">&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum14" style="color: #606060">  14:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">input</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">=&quot;txtUserPass&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;password&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum15" style="color: #606060">  15:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">ASP:RequiredFieldValidator</span> <span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">=&quot;txtUserPass&quot;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum16" style="color: #606060">  16:</span>           <span style="color: #ff0000">Display</span><span style="color: #0000ff">=&quot;Static&quot;</span> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">=&quot;*&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum17" style="color: #606060">  17:</span>           <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;vUserPass&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum18" style="color: #606060">  18:</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum19" style="color: #606060">  19:</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">tr</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum20" style="color: #606060">  20:</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">tr</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum21" style="color: #606060">  21:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span>Persistent Cookie:<span style="color: #0000ff">&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum22" style="color: #606060">  22:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">ASP:CheckBox</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">=&quot;chkPersistCookie&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #ff0000">autopostback</span><span style="color: #0000ff">=&quot;false&quot;</span> <span style="color: #0000ff">/&gt;&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum23" style="color: #606060">  23:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">td</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum24" style="color: #606060">  24:</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">tr</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum25" style="color: #606060">  25:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">table</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum26" style="color: #606060">  26:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">input</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;submit&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;Logon&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;cmdLogin&quot;</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">p</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">p</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum27" style="color: #606060">  27:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:Label</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">=&quot;lblMsg&quot;</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">=&quot;red&quot;</span> <span style="color: #ff0000">Font-Name</span><span style="color: #0000ff">=&quot;Verdana&quot;</span> <span style="color: #ff0000">Font-Size</span><span style="color: #0000ff">=&quot;10&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum28" style="color: #606060">  28:</span>                         </pre>
<p><!--CRLF--></div>
</p></div>
<li>This Web Form is used to present a logon form to users so that they can provide their user name and password to log on to the application. </li>
<li>Switch to Design view, and save the page.</li>
</ol>
<h2>Code the Event Handler So That It Validates the User Credentials</h2>
<p>This section presents the code that is placed in the code-behind page (Logon.aspx.cs). </p>
<ol>
<li>Double-click <strong>Logon</strong> to open the Logon.aspx.cs file. </li>
<li>Import the required namespaces in the code-behind file:</li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> using System.Data.SqlClient;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span> using System.Web.Security;</pre>
<p><!--CRLF--></div>
</p></div>
<li>Create a <b>ValidateUser</b> function to validate the user credentials by looking in the database. (Make sure that you change the Connection string to point to your database).</li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> ValidateUser( <span style="color: #0000ff">string</span> userName, <span style="color: #0000ff">string</span> passWord )</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060">   3:</span>     SqlConnection conn;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060">   4:</span>     SqlCommand cmd;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #0000ff">string</span> lookupPassword = <span style="color: #0000ff">null</span>;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum6" style="color: #606060">   6:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #008000">// Check for invalid userName.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum8" style="color: #606060">   8:</span>     <span style="color: #008000">// userName must not be null and must be between 1 and 15 characters.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum9" style="color: #606060">   9:</span>     <span style="color: #0000ff">if</span> ( (  <span style="color: #0000ff">null</span> == userName ) || ( 0 == userName.Length ) || ( userName.Length &gt; 15 ) )</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum10" style="color: #606060">  10:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum11" style="color: #606060">  11:</span>         System.Diagnostics.Trace.WriteLine( <span style="color: #006080">&quot;[ValidateUser] Input validation of userName failed.&quot;</span> );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum12" style="color: #606060">  12:</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum13" style="color: #606060">  13:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum14" style="color: #606060">  14:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum15" style="color: #606060">  15:</span>     <span style="color: #008000">// Check for invalid passWord.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum16" style="color: #606060">  16:</span>     <span style="color: #008000">// passWord must not be null and must be between 1 and 25 characters.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum17" style="color: #606060">  17:</span>     <span style="color: #0000ff">if</span> ( (  <span style="color: #0000ff">null</span> == passWord ) || ( 0 == passWord.Length ) || ( passWord.Length &gt; 25 ) )</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum18" style="color: #606060">  18:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum19" style="color: #606060">  19:</span>         System.Diagnostics.Trace.WriteLine( <span style="color: #006080">&quot;[ValidateUser] Input validation of passWord failed.&quot;</span> );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum20" style="color: #606060">  20:</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum21" style="color: #606060">  21:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum22" style="color: #606060">  22:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum23" style="color: #606060">  23:</span>     <span style="color: #0000ff">try</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum24" style="color: #606060">  24:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum25" style="color: #606060">  25:</span>         <span style="color: #008000">// Consult with your SQL Server administrator for an appropriate connection</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum26" style="color: #606060">  26:</span>         <span style="color: #008000">// string to use to connect to your local SQL Server.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum27" style="color: #606060">  27:</span>         conn = <span style="color: #0000ff">new</span> SqlConnection( <span style="color: #006080">&quot;server=localhost;Integrated Security=SSPI;database=pubs&quot;</span> );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum28" style="color: #606060">  28:</span>         conn.Open();</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum29" style="color: #606060">  29:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum30" style="color: #606060">  30:</span>         <span style="color: #008000">// Create SqlCommand to select pwd field from users table given supplied userName.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum31" style="color: #606060">  31:</span>         cmd = <span style="color: #0000ff">new</span> SqlCommand( <span style="color: #006080">&quot;Select pwd from users where uname=@userName&quot;</span>, conn );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum32" style="color: #606060">  32:</span>         cmd.Parameters.Add( <span style="color: #006080">&quot;@userName&quot;</span>, SqlDbType.VarChar, 25 );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum33" style="color: #606060">  33:</span>         cmd.Parameters[<span style="color: #006080">&quot;@userName&quot;</span>].Value = userName;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum34" style="color: #606060">  34:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum35" style="color: #606060">  35:</span>         <span style="color: #008000">// Execute command and fetch pwd field into lookupPassword string.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum36" style="color: #606060">  36:</span>         lookupPassword = (<span style="color: #0000ff">string</span>) cmd.ExecuteScalar();</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum37" style="color: #606060">  37:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum38" style="color: #606060">  38:</span>         <span style="color: #008000">// Cleanup command and connection objects.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum39" style="color: #606060">  39:</span>         cmd.Dispose();</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum40" style="color: #606060">  40:</span>         conn.Dispose();</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum41" style="color: #606060">  41:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum42" style="color: #606060">  42:</span>     <span style="color: #0000ff">catch</span> ( Exception ex )</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum43" style="color: #606060">  43:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum44" style="color: #606060">  44:</span>         <span style="color: #008000">// Add error handling here for debugging.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum45" style="color: #606060">  45:</span>         <span style="color: #008000">// This error message should not be sent back to the caller.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum46" style="color: #606060">  46:</span>         System.Diagnostics.Trace.WriteLine( <span style="color: #006080">&quot;[ValidateUser] Exception &quot;</span> + ex.Message );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum47" style="color: #606060">  47:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum48" style="color: #606060">  48:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum49" style="color: #606060">  49:</span>     <span style="color: #008000">// If no password found, return false.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum50" style="color: #606060">  50:</span>     <span style="color: #0000ff">if</span> ( <span style="color: #0000ff">null</span> == lookupPassword ) </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum51" style="color: #606060">  51:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum52" style="color: #606060">  52:</span>         <span style="color: #008000">// You could write failed login attempts here to event log for additional security.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum53" style="color: #606060">  53:</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum54" style="color: #606060">  54:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum55" style="color: #606060">  55:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum56" style="color: #606060">  56:</span>     <span style="color: #008000">// Compare lookupPassword and input passWord, using a case-sensitive comparison.</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum57" style="color: #606060">  57:</span>     <span style="color: #0000ff">return</span> ( 0 == <span style="color: #0000ff">string</span>.Compare( lookupPassword, passWord, <span style="color: #0000ff">false</span> ) );</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum58" style="color: #606060">  58:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum59" style="color: #606060">  59:</span> }</pre>
<p><!--CRLF--></div>
</p></div>
<li>You can use one of two methods to generate the forms authentication cookie and redirect the user to an appropriate page in the <b>cmdLogin_ServerClick</b> event. Sample code is provided for both scenarios. Use either of them according to your requirement. </li>
<ul>
<li>Call the <b>RedirectFromLoginPage</b> method to automatically generate the forms authentication cookie and redirect the user to an appropriate page in the <b>cmdLogin_ServerClick</b> event:</li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> cmdLogin_ServerClick(<span style="color: #0000ff">object</span> sender, System.EventArgs e)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #0000ff">if</span> (ValidateUser(txtUserName.Value,txtUserPass.Value) )</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060">   4:</span>     FormsAuthentication.RedirectFromLoginPage(txtUserName.Value,</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060">   5:</span>         chkPersistCookie.Checked);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #0000ff">else</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum7" style="color: #606060">   7:</span>         Response.Redirect(<span style="color: #006080">&quot;logon.aspx&quot;</span>, <span style="color: #0000ff">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum8" style="color: #606060">   8:</span> }</pre>
<p><!--CRLF--></div>
</p></div>
<li>Generate the authentication ticket, encrypt it, create a cookie, add it to the response, and redirect the user. This gives you more control in how you create the cookie. You can also include custom data along with the <b>FormsAuthenticationTicket</b> in this case.</li>
</ul>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> cmdLogin_ServerClick(<span style="color: #0000ff">object</span> sender, System.EventArgs e)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060">   3:</span>    <span style="color: #0000ff">if</span> (ValidateUser(txtUserName.Value,txtUserPass.Value) )</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060">   4:</span>    {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060">   5:</span>       FormsAuthenticationTicket tkt;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum6" style="color: #606060">   6:</span>       <span style="color: #0000ff">string</span> cookiestr;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum7" style="color: #606060">   7:</span>       HttpCookie ck;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum8" style="color: #606060">   8:</span>       tkt = <span style="color: #0000ff">new</span> FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now, </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum9" style="color: #606060">   9:</span> DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, <span style="color: #006080">&quot;your custom data&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum10" style="color: #606060">  10:</span>       cookiestr = FormsAuthentication.Encrypt(tkt);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum11" style="color: #606060">  11:</span>       ck = <span style="color: #0000ff">new</span> HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum12" style="color: #606060">  12:</span>       <span style="color: #0000ff">if</span> (chkPersistCookie.Checked)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum13" style="color: #606060">  13:</span>       ck.Expires=tkt.Expiration;    </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum14" style="color: #606060">  14:</span>             ck.Path = FormsAuthentication.FormsCookiePath; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum15" style="color: #606060">  15:</span>       Response.Cookies.Add(ck);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum16" style="color: #606060">  16:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum17" style="color: #606060">  17:</span>       <span style="color: #0000ff">string</span> strRedirect;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum18" style="color: #606060">  18:</span>       strRedirect = Request[<span style="color: #006080">&quot;ReturnUrl&quot;</span>];</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum19" style="color: #606060">  19:</span>       <span style="color: #0000ff">if</span> (strRedirect==<span style="color: #0000ff">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum20" style="color: #606060">  20:</span>             strRedirect = <span style="color: #006080">&quot;default.aspx&quot;</span>;</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum21" style="color: #606060">  21:</span>          Response.Redirect(strRedirect, <span style="color: #0000ff">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum22" style="color: #606060">  22:</span>    }</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum23" style="color: #606060">  23:</span>    <span style="color: #0000ff">else</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum24" style="color: #606060">  24:</span>       Response.Redirect(<span style="color: #006080">&quot;logon.aspx&quot;</span>, <span style="color: #0000ff">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum25" style="color: #606060">  25:</span> }</pre>
<p><!--CRLF--></div>
</p></div>
<li>Make sure that the following code is added to the <b>InitializeComponent</b> method in the code that the Web Form Designer generates:</li>
</ol>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1: </span><span style="color: #0000ff">this</span>.cmdLogin.ServerClick += <span style="color: #0000ff">new</span> System.EventHandler(<span style="color: #0000ff">this</span>.cmdLogin_ServerClick);</pre>
<p><!--CRLF--></div>
</div>
<h2>Create a Default.aspx Page</h2>
<p>This section creates a test page to which users are redirected after they authenticate. If users browse to this page without first logging on to the application, they are redirected to the logon page. </p>
<ol>
<li>Rename the existing WebForm1.aspx page as Default.aspx, and open it in the editor. </li>
<li>Switch to HTML view, and copy the following code between the &lt;form&gt; tags: </li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">input</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;submit&quot;</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=&quot;SignOut&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">=&quot;cmdSignOut&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<p><!--CRLF--></div>
</p></div>
<li>This button is used to log off the forms authentication session. </li>
<li>Switch to Design view, and save the page. </li>
<li>Import the required namespaces in the code-behind file:</li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">using</span> System.Web.Security;</pre>
<p><!--CRLF--></div>
</p></div>
<li>Double-click <b>SignOut</b> to open the code-behind page (Default.aspx.cs), and copy the following code in the <b>cmdSignOut_ServerClick</b> event handler:</li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> cmdSignOut_ServerClick(<span style="color: #0000ff">object</span> sender, System.EventArgs e)</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060">   3:</span>    FormsAuthentication.SignOut();</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060">   4:</span>    Response.Redirect(<span style="color: #006080">&quot;logon.aspx&quot;</span>, <span style="color: #0000ff">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060">   5:</span> }</pre>
<p><!--CRLF--></div>
</p></div>
<li>Make sure that the following code is added to the <b>InitializeComponent</b> method in the code that the Web Form Designer generates:</li>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">this</span>.cmdSignOut.ServerClick += <span style="color: #0000ff">new</span> System.EventHandler(<span style="color: #0000ff">this</span>.cmdSignOut_ServerClick);</pre>
<p><!--CRLF--></div>
</p></div>
<li>Save and compile the project. You can now use the application.</li>
</ol>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/04/30/form-based-authentication-in-aspnet/" target="_blank"><img src="http://tayyab.xenoglaux-solutions.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/04/30/form-based-authentication-in-aspnet/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://tayyab.xenoglaux-solutions.com/2009/04/30/form-based-authentication-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Simple Member Login Area Using PHP</title>
		<link>http://tayyab.xenoglaux-solutions.com/2009/03/31/creating-simple-member-login-area-using-php/</link>
		<comments>http://tayyab.xenoglaux-solutions.com/2009/03/31/creating-simple-member-login-area-using-php/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 15:54:59 +0000</pubDate>
		<dc:creator>tayyabtariq</dc:creator>
				<category><![CDATA[PHP & MySQL]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Cookie Login]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[PHP Authentication]]></category>
		<category><![CDATA[PHP Login]]></category>
		<category><![CDATA[PHP Members Area]]></category>

		<guid isPermaLink="false">http://tayyabtariq.wordpress.com/?p=11</guid>
		<description><![CDATA[This tutorial is aimed at creating a simple login/members area using PHP MySQL.
I will waste no time and get straight down to business. The tutorial is based on 6 easy steps.
Step 1:
Creating a table in the database.
I have created a very simple table that has only two columns; username and password.
Here is the SQL:
CREATE TABLE [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial is aimed at creating a simple login/members area using PHP MySQL.<span id="more-11"></span></p>
<p>I will waste no time and get straight down to business. The tutorial is based on 6 easy steps.</p>
<p><strong>Step 1:</strong></p>
<p>Creating a table in the database.</p>
<p>I have created a very simple table that has only two columns; username and password.</p>
<p>Here is the SQL:</p>
<blockquote><p>CREATE TABLE `userstable` (<br />
`userName` varchar(20) NOT NULL default &#8221;,<br />
`password` varchar(20) NOT NULL default &#8221;,<br />
PRIMARY KEY  (`userName`)<br />
) ENGINE=MyISAM DEFAULT CHARSET=latin1;</p></blockquote>
<p><strong>Step 2:</strong></p>
<p>Create a connection to the database. Although the file below is meant only for a database connection I have taken the liberty of using it to save some general purpose settings as well.</p>
<blockquote><p>//dbConfig.php</p>
<p>&lt;?php<br />
/*</p>
<ul>
<li>The config file for the database connection and variables</li>
<li>change the database name and username and password</li>
<li>/</li>
</ul>
<p>//variables for the databse connection<br />
$serverName = &#8220;localhost&#8221;;<br />
$userName = &#8220;manager&#8221;;<br />
$password = &#8220;&#8221;;<br />
$dbName = &#8220;testdatabase&#8221;;</p>
<p>$conn = mysql_pconnect($serverName, $userName, $password);<br />
if (!$conn)<br />
{<br />
//print error message, the echo command support html encodeing.<br />
echo(&#8217;The connection to the database could not be established!&#8217;);<br />
die(&#8217;The connection to the database could not be established!&#8217;);<br />
}<br />
else<br />
{<br />
// select the database which you wish to opereate<br />
mysql_select_db($dbName);</p>
<p>}</p>
<p>// other variable<br />
$loginSuccess = &#8220;phpMembersArea.php&#8221;;<br />
$RegisterSuccess = &#8220;phpRegister.php?op=thanks&#8221;;<br />
$loginRequired = &#8220;phpLogin.php?op=loginFirst&#8221;;<br />
$timeout = 3600;<br />
$authenticatioMethod = &#8220;cookie&#8221;;</p>
<p>function CheckLogin() {</p>
<p>// fucntion that checks if some is logged in or not<br />
global $authenticatioMethod;<br />
if (strcmp($authenticatioMethod ,&#8221;cookie&#8221;) == 0)//we have choosen to use cookies<br />
{</p>
<p>if (!isset($_COOKIE["login"]))<br />
{<br />
return null;<br />
}<br />
else<br />
{<br />
return $_COOKIE["login"];</p>
<p>}<br />
}<br />
else// we are using session based authentication<br />
{<br />
if (!$_Session["userID"] || $_Session["valid_expire_time"] &lt; time())<br />
{<br />
$_Session["userID"]  = null;<br />
$_Session["valid_expire_time"] = time()-1;<br />
session_destroy();<br />
return null;<br />
}<br />
else<br />
{<br />
return $_Session["userID"];<br />
}<br />
}<br />
return null;<br />
}<br />
function RedirectTo($url)<br />
{<br />
//I have to use this function because the php function header can only be called<br />
// if no output has been sent<br />
// this solution uses java scripts so beware<br />
echo(&#8217;&lt;script type=&#8221;text/javascript&#8221;&gt; document.location = &#8221;.$url.&#8221;; &lt;/script&gt;&#8217;);<br />
}<br />
?&gt;</p></blockquote>
<p><strong>Step 3:</strong></p>
<p>Create a Registeration Page.</p>
<p>I provide a simple registeration page, where you can enter two fields, username and password.</p>
<blockquote><p>//phpRegister.php<br />
&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=UTF-8&#8243;&gt;<br />
&lt;title&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;form action=&#8221;?op=register&#8221; method=&#8221;POST&#8221;&gt;<br />
Username: &lt;input name=&#8221;userID&#8221; MAXLENGTH=&#8221;16&#8243;&gt;&lt;br /&gt;<br />
Password: &lt;input type=&#8221;password&#8221; name=&#8221;password&#8221; MAXLENGTH=&#8221;16&#8243;&gt;&lt;br /&gt;<br />
&lt;input type=&#8221;submit&#8221;&gt;<br />
&lt;/form&gt;<br />
&lt;?php<br />
// first we include the dbconfig file<br />
// note that we do not need to open the connection<br />
// when the file is included and this page is loaded, the code is automatically executed<br />
echo(&#8217;hello&#8217;);<br />
include (&#8221;dbConfig.php&#8221;);</p>
<p>/*</p>
<ul>
<li>Here is the plan of action, this is the page that contains the registeration form</li>
<li>also this is the page that will connect to the database and execute the insert query</li>
<li>so we need to know if the page is being run from a</li>
<li>/</li>
</ul>
<p>// we suppose that a variable named op would be passed with a value<br />
// register if there is a registeration request.<br />
if ($_GET["op"] == &#8220;register&#8221;)<br />
{</p>
<p>if (!($userID = $_POST["userID"]) )<br />
{<br />
echo(&#8217;UserName field is missing!&#8217;);<br />
}<br />
else if (!($password = $_POST["password"]))<br />
{<br />
echo(&#8217;Password field is missing!&#8217;);<br />
}</p>
<p>$query = &#8220;INSERT INTO `USERSTABLE` VALUES( &#8216;&#8221;.$_POST["userID"].&#8221;&#8216;, Password(&#8217;&#8221;.$_POST["password"].&#8221;&#8216;))&#8221;;<br />
//note that my sql requires the password filed to be casted<br />
// also note that . is the string concatenation operator<br />
// also not the &#8220; around the table name</p>
<p>$result = mysql_query($query, $conn);<br />
//you can also redirect to a different page</p>
<p>if (!$result )<br />
{<br />
// make sure that the user was inserted<br />
echo(&#8217;&lt;br&gt;&lt;h2&gt;The user could not be inserted&lt;br&gt;&#8217;);<br />
echo(&#8217;The error cant be displayed&lt;/h2&gt;&#8217;);<br />
}<br />
else<br />
{</p>
<p>REdirectTo($RegisterSuccess);<br />
}</p>
<p>}<br />
else if ($_GET["op"] == &#8220;thanks&#8221;)<br />
{<br />
echo(&#8217;&lt;br&gt;&lt;h2&gt;The user was added successfully!&lt;/h2&gt;&#8217;);<br />
}<br />
//The web form for input ability</p>
<p>?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>After this step you have successfully created a user account. All you need to do now is to create a login page.</p>
<p><strong>Step 4:</strong></p>
<p>The plan of action for our login page is that we pass it an query string argument, &#8216;op&#8217; that dictates what the page does. If the value of this variable is &#8216;login&#8217; the page gets the POST information and tries to login.</p>
<blockquote><p>//phpLogin.php</p>
<p>&lt;?php<br />
include (&#8217;dbConfig.php&#8217;);<br />
if ($_GET["op"] == &#8220;login&#8221;)//check if this is a login request<br />
{<br />
$query = &#8220;Select * from `userstable` where `userName`=&#8217;&#8221;.$_POST["userID"].&#8221;&#8216; AND `password`=Password(&#8217;&#8221;.$_POST["password"].&#8221;&#8216;) &#8220;;</p>
<p>$result = mysql_query($query, $conn);<br />
$obj = @mysql_fetch_object($result);<br />
if ($obj)<br />
{<br />
// means sucessful login<br />
$loginSucessful = 1;<br />
//create session variables<br />
// i will create both a login cookie<br />
// and session variables<br />
// and show how to use both for authentication</p>
<p>$_SESSION["valid_userID"] = $_POST["userID"];<br />
$_SESSION["valide_time"] = time();<br />
$_SESSION["valid_expire_time"] = time()+$timeout;</p>
<p>//set the cookies<br />
//i create a cookie where i set the cookie information to the user name<br />
// the userID can be encrypted also for better security.<br />
setcookie(&#8221;login&#8221;, $_POST["userID"], time()+$timeout);</p>
<p>// create a cookie<br />
}<br />
else<br />
{<br />
$loginSucessful = 0;<br />
}</p>
<p>if ($loginSucessful == 1)<br />
{<br />
//login has succeeded proceed to members area<br />
if ($_GET["referrer"] )<br />
{<br />
// if we were sent to the login page due to some request of a members area page<br />
// go to that page<br />
RedirectTo($_POST["referrer"]);<br />
}<br />
else<br />
{<br />
RedirectTo($loginSuccess);<br />
}<br />
}<br />
else<br />
{<br />
echo(&#8217;&lt;br&gt;&lt;h2&gt;Login Information is not correct&lt;br&gt;&#8217;.$_POST["userID"].&#8217; does not exist or password is incorrect&lt;/h2&gt;&#8217;);<br />
}<br />
}<br />
else if($_GET["op"] == &#8220;loginFirst&#8221;)<br />
{<br />
echo(&#8217;&lt;br&gt;&lt;h2&gt;You must login first.&lt;/h2&gt;&#8217;);<br />
}<br />
?&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=UTF-8&#8243;&gt;<br />
&lt;title&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;?php echo(&#8221; &lt;form action=&#8221;?op=login&#8221; method=&#8221;POST&#8221;&gt;&#8221;); ?&gt;<br />
&lt;table&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;<br />
UserID:<br />
&lt;/td&gt;<br />
&lt;td&gt;<br />
&lt;input type = &#8220;text&#8221; name=&#8221;userID&#8221; maxlength=&#8221;16&#8243;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;<br />
Password:<br />
&lt;/td&gt;<br />
&lt;td&gt;<br />
&lt;input type = &#8220;password&#8221; name=&#8221;password&#8221; maxlength=&#8221;16&#8243;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;</p>
<p>&lt;/td&gt;<br />
&lt;td&gt;<br />
&lt;input type =&#8221;submit&#8221; name=&#8221;subit&#8221; maxlength=&#8221;16&#8243;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/form&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>Caution: There must be nothing before the &#8216;&lt;php&#8217; at the start of the page, if there is something the cookie would not be created. It took me some time to figure this out. Keeping this in mind can save a lot of time. Even an empty line or a space can mess things up.</p>
<p>PS: When a members area page is accessed without being logged in, the page redirects to the login page giving it a &#8216;referrer&#8217; argument. I however could not make it work, if anyone can help please look at:</p>
<p>&lt;?php echo(&#8221; &lt;form action=&#8221;?op=login&#8221; method=&#8221;POST&#8221;&gt;&#8221;); ?&gt;</p>
<p>I was trying to replace this with</p>
<p>&lt;?php echo(&#8221; &lt;form action=&#8221;?op=login&amp;referrer=&#8221; . $_GET["referrer"]  . &#8220;&#8221; method=&#8221;POST&#8221;&gt;&#8221;); ?&gt;</p>
<p>However, whenever there was a valid referrer the username and password is not verified, the page works fine otherwise.</p>
<p><strong>Step 5:</strong></p>
<p>The members area page.</p>
<blockquote><p>//phpMembersArea.php</p>
<p>&lt;?php<br />
session_start();<br />
include (&#8217;dbConfig.php&#8217;);<br />
$loggedInUser = CheckLogin();<br />
if (!$loggedInUser)// no one is logged in<br />
{<br />
echo(&#8217;You are not logged in&#8217;);<br />
RedirectTo(&#8221;phpLogin.php?referrer=phpMembersArea.php&#8221;);<br />
}<br />
else<br />
{<br />
echo(&#8217;&lt;h2&gt;Welcome &#8216;.$loggedInUser.&#8217;!&lt;/h2&gt;&lt;br&gt;&#8217;);<br />
}<br />
?&gt;<br />
&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=UTF-8&#8243;&gt;<br />
&lt;title&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h1&gt;This is the members area&lt;/h1&gt;<br />
&lt;br&gt;<br />
&lt;br&gt;<br />
&lt;a href = &#8220;phpLogout.php&#8221;&gt;Logout&lt;/a&gt;<br />
&lt;?php</p>
<p>?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>The page calls the CheckLogin() function defined in the dbConfig.php. This function checks the <a href="http://w3schools.com/php/php_cookies.asp" target="_blank">cookie</a> or the <a href="http://w3schools.com/php/php_sessions.asp" target="_blank">session variable </a>for login information. If this information is found the login proceeds otherwise the user is redirected to the login page.</p>
<p><strong>Step 6:</strong></p>
<p>The logout page simply deletes the <a href="http://w3schools.com/php/php_cookies.asp" target="_blank">cookie </a>and the <a href="http://w3schools.com/php/php_sessions.asp" target="_blank">session</a>.</p>
<blockquote><p>//phpLogout.php</p>
<p>&lt;?php<br />
setcookie(&#8221;login&#8221;, &#8220;&#8221;, time()-100);<br />
include (&#8217;DbConfig.php&#8217;);</p>
<p>RedirectTo(&#8221;index.php&#8221;);<br />
?&gt;<br />
&lt;!&#8211;<br />
To change this template, choose Tools | Templates<br />
and open the template in the editor.<br />
&#8211;&gt;<br />
&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=UTF-8&#8243;&gt;<br />
&lt;title&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>And there you go, you are done.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/03/31/creating-simple-member-login-area-using-php/" target="_blank"><img src="http://tayyab.xenoglaux-solutions.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/03/31/creating-simple-member-login-area-using-php/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://tayyab.xenoglaux-solutions.com/2009/03/31/creating-simple-member-login-area-using-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Login Sessions: Cookies vs Session Variable</title>
		<link>http://tayyab.xenoglaux-solutions.com/2009/03/31/login-sessions-cookies-vs-session-variable/</link>
		<comments>http://tayyab.xenoglaux-solutions.com/2009/03/31/login-sessions-cookies-vs-session-variable/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 18:07:31 +0000</pubDate>
		<dc:creator>tayyabtariq</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[login security]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[session variable]]></category>

		<guid isPermaLink="false">http://tayyabtariq.wordpress.com/?p=3</guid>
		<description><![CDATA[Cookies and Session variables are two ways, implementation members areas and user login/security. The two methods are a bargain between server performance and security. Server side security gives better security but is just not practical for larger number of users and can seriously deteriorate server performance. On the other hand user side security is far more efficient and lighter on the server however is far more susceptible to security breaches.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-9" title="cookie2" src="http://tayyabtariq.files.wordpress.com/2009/03/cookie2.jpeg" alt="cookie2" width="100" height="121" />Cookies and Session variables are two ways, implementation members areas and user login/security. The two methods are a bargain between server performance and security. Server side security gives better security but is just not practical for larger number of users and can seriously deteriorate server performance. On the other hand user side security is far more efficient and lighter on the server however is far more susceptible to security breaches.</p>
<p><span id="more-3"></span>Although I assume a basic knowledge of what cookies and sessions are, we start with a quick review.</p>
<blockquote><p><strong><em>&#8220;HTTP cookies, more commonly referred to as <a title="World Wide Web" href="http://en.wikipedia.org/wiki/World_Wide_Web">Web</a> cookies, tracking cookies or just cookies, are parcels of text sent by a <a title="Web server" href="http://en.wikipedia.org/wiki/Web_server">server</a> to a Web <a title="Client (computing)" href="http://en.wikipedia.org/wiki/Client_%28computing%29">client</a><a title="Web browser" href="http://en.wikipedia.org/wiki/Web_browser">browser</a>) and then sent back unchanged by client each time it accesses that server. <a title="Hypertext Transfer Protocol" href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a> cookies are used for <a title="Authentication" href="http://en.wikipedia.org/wiki/Authentication">authenticating</a>, session tracking (state maintenance), and maintaining specific information about users, such as site preferences or the contents of their <a class="mw-redirect" title="Electronic shopping cart" href="http://en.wikipedia.org/wiki/Electronic_shopping_cart">electronic shopping carts</a>. The term &#8220;cookie&#8221; is derived from &#8220;<a title="Magic cookie" href="http://en.wikipedia.org/wiki/Magic_cookie">magic cookie</a>,&#8221; a well-known concept in <a class="mw-redirect" title="UNIX" href="http://en.wikipedia.org/wiki/UNIX">UNIX</a> computing which inspired both the idea and the name of HTTP cookies. Some alternatives to cookies exist, but each has its own uses, advantages, and drawbacks.&#8221;</em> (usually a </strong></p>
</blockquote>
<blockquote>
<p style="text-align:right;"><strong><em>&#8211; Wikipedia (http://en.wikipedia.org/wiki/HTTP_cookie)</em></strong></p>
</blockquote>
<blockquote>
<p style="text-align:left;"><em></p>
<p></em></p>
</blockquote>
<blockquote><p><em><strong>&#8220;In <a title="Computer science" href="http://en.wikipedia.org/wiki/Computer_science">computer science</a>, in particular <a title="Computer network" href="http://en.wikipedia.org/wiki/Computer_network">networking</a>, a </strong><strong>session is a semi-permanent interactive information exchange, also known as a dialogue, a conversation or a meeting, between two or more communicating devices, or between a computer and user (see <a title="Login session" href="http://en.wikipedia.org/wiki/Login_session">Login session</a>). A session is set up or established at a certain point in time, and torn down at a later point in time. An established communication session may involve more than one message in each direction. A session is typically, but not always, <a class="mw-redirect" title="Stateful" href="http://en.wikipedia.org/wiki/Stateful">stateful</a>, meaning that at least one of the communicating parts needs to save information about the session history in order to be able to communicate, as opposed to <a title="Stateless server" href="http://en.wikipedia.org/wiki/Stateless_server">stateless</a> communication, where the communication consists of independent requests with responses.</strong></em></p>
<p><em><strong>&#8230;</strong></em></p>
<p><em><strong><a class="mw-redirect" title="HTTP" href="http://en.wikipedia.org/wiki/HTTP">HTTP</a> sessions, which may allow <a title="Dynamic web page" href="http://en.wikipedia.org/wiki/Dynamic_web_page">dynamic web pages</a>, i.e. interactive web pages, as opposed to <a title="Static web page" href="http://en.wikipedia.org/wiki/Static_web_page">static web pages</a>.&#8221;</strong></em></p>
<p style="text-align:right;"><em><strong>&#8211;Wikipedia (http://en.wikipedia.org/wiki/Session_(computer_science))</strong></em></p>
</blockquote>
<blockquote><p><em><strong>&#8220;<span class="mw-headline">Server side web sessions</span></strong></em></p>
<p><em><strong>Server-side sessions are handy and efficient, but can become difficult to handle in conjunction with load-balancing/high-availability systems and are not usable at all in embedded systems with no storage. The load-balancing problem can be solved by using shared storage or by applying forced peering between each client and a single server in the cluster, although this can compromise system efficiency and load distribution.</strong></em></p>
<p><em><strong>A method of using server-side sessions in systems without mass-storage is to reserve a portion of RAM for storage of session data. This method is applicable for servers with a limited number of clients (e.g. router or access point with infrequent or disallowed access to more than one client at a time).</strong></em></p>
<p><em><strong>In the two scenarios above, using client-side sessions could provide advantages over server-side sessions: in the first case by removing the limitations applied to load-balancing algorithms (which usually translates to load distribution optimisation), and in the second case by allowing the use of sessions in web applications when server disk space or RAM is not available or sufficient for this storage.&#8221;</strong></em></p>
<p style="text-align:right;"><em><strong>&#8211;Wikipedia (http://en.wikipedia.org/wiki/Session_(computer_science))</strong></em></p>
</blockquote>
<p style="text-align:left;">Now that we have enough insight into what server side and user side security and session maintenance means, we can get down to the business of comparing the two. As it is evident up to here that the server side security (web sessions) are far more secure. There is no information that can be changed by the user, unless of course your server is hacked but then <em><strong>&#8220;&#8230;you have a bigger fish to fry&#8230;&#8221;</strong></em>, log in sessions would be the leasat of your worries. The drawback however is that the server must maintain all the information of the sessions, that too in the RAM. This can be a considerable over head for the server, not to mention can degrade performance to a great extent and may even cause the server to run out of memory. On the other hand if the session variables are to be maintained jointly on the user system and the server, this over head is avoided. The problem however is that<em> &#8217;smart&#8217;</em> users can control what cookies they send, thereby compromising security. Forging cookies is the most common way the user accounts are hacked. I sill remember the enormous number of articles on the internet regarding hacking hotmail account using cookies till hotmail solved the problem*.</p>
<p style="text-align:left;">Cookie based security is the most widely used these days and seems to be the clear &#8216;practical&#8217; winner in the face off. However, it clearly is less secure. So I put up these questions as some food for thought.</p>
<p style="text-align:left;">Since the main problem with server side security is that of memory use over head. What if web languages like PHP, C# etc provide a way to store the session information on permanent storage and implement a simple &#8216;cache&#8217; like system to keep only the recently used information in the RAM (Though I would suggest that the recently used information be dicarded to permanent storage if needed). This would make the server a little slower but would surely be far more secure.</p>
<p style="text-align:left;">PS: * How did hotmail solve the problem?</p>
<blockquote>
<blockquote>
<p style="text-align:right;"></blockquote>
</blockquote>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/03/31/login-sessions-cookies-vs-session-variable/" target="_blank"><img src="http://tayyab.xenoglaux-solutions.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/03/31/login-sessions-cookies-vs-session-variable/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://tayyab.xenoglaux-solutions.com/2009/03/31/login-sessions-cookies-vs-session-variable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

