<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Code The World — Simple login form]]></title>
	<link rel="self" href="https://codetheworld.com/extern.php?action=feed&amp;tid=77&amp;type=atom" />
	<updated>2008-06-16T04:10:59Z</updated>
	<generator>PunBB</generator>
	<id>https://codetheworld.com/viewtopic.php?id=77</id>
		<entry>
			<title type="html"><![CDATA[Simple login form]]></title>
			<link rel="alternate" href="https://codetheworld.com/viewtopic.php?pid=219#p219" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>function login(){
    
    switch($_GET[&#039;op&#039;]){
    
        case &#039;submit&#039;:
        $clean = array();
        $mysql = array();
    
        $now = time();
        $max = $now - 30;
    
        $salt = $sitekey;
    
        if (ctype_alnum($_POST[&#039;username&#039;])){
          $clean[&#039;username&#039;] = $_POST[&#039;username&#039;];
        
        }else{
          
          echo $loginform;
       
        }
    
        $clean[&#039;password&#039;] = md5($salt . md5($_POST[&#039;password&#039;] . $salt));
        $mysql[&#039;username&#039;] = mysql_real_escape_string($clean[&#039;username&#039;]);
    
        $sql = &quot;SELECT last_failure, password, access_level
                FROM   users
                WHERE  username = &#039;{$mysql[&#039;username&#039;]}&#039;&quot;;
    
        if ($result = mysql_query($sql)){
        
          if (mysql_num_rows($result)){
          
            $record = mysql_fetch_assoc($result);
            $access = $record[&#039;access_level&#039;];
            
            if ($record[&#039;last_failure&#039;]&gt; $max){
              /* Less than 15 seconds since last failure */
              echo &quot;Less than 30 seconds since last failure&quot;;
            
            }elseif ($record[&#039;password&#039;] == $clean[&#039;password&#039;]){
                
                $user = $mysql[&#039;username&#039;];
                session_start();
                $_SESSION[&#039;access_level&#039;] = $access;
                $_SESSION[&#039;username&#039;] = $user;
              
             echo &quot;&lt;META HTTP-EQUIV=Refresh CONTENT=\&quot;0; URL=index.php\&quot;&gt;&quot;; 
            
            }else{
            
              /* Failed Login */
    
              $sql = &quot;UPDATE users
                      SET    last_failure = &#039;$now&#039;
                      WHERE  username = &#039;{$mysql[&#039;username&#039;]}&#039;&quot;;
    
              mysql_query($sql);
              
              echo &quot;Login Failed Username Not Found or Wrong Password&quot;;
            }
          
          }else{
          
            /* Invalid Username */
            echo &quot;Invalid Username!!&quot;;
          }
          
        }else{
          /* Error */
          echo &quot;System Error!!&quot;;
        }
        
        break;
        
        default:
        echo &quot;&lt;blockquote&gt;&lt;form action=\&quot;login.php?action=login&amp;op=submit\&quot; method=\&quot;post\&quot; enctype=\&quot;application/x-www-form-urlencoded\&quot;&gt;
                  &lt;label&gt;Username&lt;br&gt;
                  &lt;input type=\&quot;text\&quot; name=\&quot;username\&quot;&gt;
                  &lt;/label&gt;
                  &lt;br&gt;
                  &lt;label&gt;Password&lt;br&gt;
                  &lt;input type=\&quot;password\&quot; name=\&quot;password\&quot;&gt;
                  &lt;/label&gt;
                  &lt;br&gt;
                  &lt;label&gt;
                  &lt;input type=\&quot;submit\&quot; name=\&quot;Submit\&quot; value=\&quot;Login\&quot;&gt;
                  &lt;/label&gt;
                &lt;/form&gt;&lt;/blockquote&gt;&quot;;
        break;
        
    
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[a3d2i2]]></name>
				<uri>https://codetheworld.com/profile.php?id=145</uri>
			</author>
			<updated>2008-06-16T04:10:59Z</updated>
			<id>https://codetheworld.com/viewtopic.php?pid=219#p219</id>
		</entry>
</feed>
