<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[PHP Forums - [Tutorial] How to make a Password Protected Page]]></title>
		<link>http://phpforums.org/topic7-tutorial-how-to-make-a-password-protected-page.html</link>
		<description><![CDATA[The most recent posts in [Tutorial] How to make a Password Protected Page.]]></description>
		<lastBuildDate>Sun, 04 Oct 2009 03:04:33 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[[Tutorial] How to make a Password Protected Page]]></title>
			<link>http://phpforums.org/post12.html#p12</link>
			<description><![CDATA[<p>Hello,</p><p>here is a tutorial on how to make a password protected page</p><p>demo: <a href="http://joeyelectric.com/demos/password.php">http://joeyelectric.com/demos/password.php</a></p><p>=========================================<br />In this tutorial we will use the crypt(); command to encrypt our passwords</p><p>files?<br />-password.php<br />==========================================</p><p>First open a new document in a text editor I use Notepad ++ (Free Opensource text editor)<br />Now Put this code in their<br /></p><div class="codebox"><pre><code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt; Password Test &lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;
&lt;h1&gt; Password Test &lt;/h1&gt;

&lt;/body&gt;
&lt;/html&gt;</code></pre></div><p>Next we will create the form:<br />you will notice that for the <strong>action=&quot;&quot;</strong> we have used &quot;<strong>&lt;?php echo $_SERVER[&#039;PHP_SELF&#039;]; ?&gt;</strong>&quot; this will make it so that all the form is processed in password.php<br /></p><div class="codebox"><pre><code>&lt;form action=&quot;&lt;?php echo $_SERVER[&#039;PHP_SELF&#039;]; ?&gt;&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;password&quot;&gt;
&lt;input type=&quot;submit&quot; name=&quot;enter&quot; value=&quot;submit&quot;&gt;
&lt;/form&gt;</code></pre></div><p>now we will add the functions to the script</p><div class="codebox"><pre><code>&lt;?php

if(isset($_GET[&#039;enter&#039;])){

$user_input = $_POST[&#039;password&#039;]; //This is the password the user typed
$user_input_crypt = crypt($user_input); //This will encrypt the password
$password = crypt(&#039;mypassword&#039;); //This is the actual password before it is encrypted about to be encrypted


if (crypt($user_input, $password) == $password) { // This determines whether the passwords match or not 
   echo &quot;&lt;font color=&#039;green&#039;&gt;Correct Password!&lt;/font&gt;&quot;; // if the password is correct this is displayed
} else {

  echo &quot;&lt;font color=&#039;red&#039;&gt;Incorrect Password!&lt;/font&gt;&lt;br&gt;&lt;br&gt;&quot;;
  echo &quot;The Password you typed came back as: $user_input_crypt &lt;br&gt; it should have been: $password&quot;; // if not this is displayed
  
  }

} else {

$password = crypt(&#039;sc55207&#039;);




?&gt;</code></pre></div><p>Now here is the code all put together:</p><div class="codebox"><pre><code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt; Password Test &lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;
&lt;h1&gt; Password Test &lt;/h1&gt;


&lt;?php

if(isset($_GET[&#039;enter&#039;])){

$user_input = $_POST[&#039;password&#039;];
$user_input_crypt = crypt($user_input);
$password = crypt(&#039;sc55207&#039;);


if (crypt($user_input, $password) == $password) {
   echo &quot;&lt;font color=&#039;green&#039;&gt;Correct Password!&lt;/font&gt;&quot;;
} else {

  echo &quot;&lt;font color=&#039;red&#039;&gt;Incorrect Password!&lt;/font&gt;&lt;br&gt;&lt;br&gt;&quot;;
  echo &quot;The Password you typed came back as: $user_input_crypt &lt;br&gt; it should have been: $password&quot;;
  
  }

} else {

$password = crypt(&#039;sc55207&#039;);




?&gt;

&lt;form action=&quot;&lt;?php echo $_SERVER[&#039;PHP_SELF&#039;]; ?&gt;&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;password&quot;&gt;
&lt;input type=&quot;submit&quot; name=&quot;enter&quot; value=&quot;submit&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (jaydesigns)]]></author>
			<pubDate>Sun, 04 Oct 2009 03:04:33 +0000</pubDate>
			<guid>http://phpforums.org/post12.html#p12</guid>
		</item>
	</channel>
</rss>
