View Single Post
ישן 05-01-15, 14:55   # 1
Jonathan Zeierman
חבר וותיק
 
מיני פרופיל
תאריך הצטרפות: Jun 2007
הודעות: 1,003

Jonathan Zeierman לא מחובר  

ייעול קוד | טופס התחברות

היי חברים,
אשמח להמלצות בנוגע לאבטחה / ייעול של הקוד אימות התחברות שלי.
PHP קוד:
<?php
###################################################################
##                     Strating Sessions.                             ##
###################################################################
session_start();
###################################################################
##                Set Cases For Functions.                         ##
###################################################################
switch ($_GET['page'])
{
    case 
'login':
        
login();
        break;
        
    default:
        
login();
        break;
}
###################################################
    
$security_code rand(000000,999999);         ##
    
$_SESSION['security_code'] = $security_code##
###################################################################
##                    Strating Login Function.                     ##
###################################################################
function Login()
{
    
################################################################################################
    ##                             Require A DB Connection File.                                      ##
    ################################################################################################
    
require_once ('db/connect.php');                                                              ##
    ################################################################################################
   
if (isset($_POST['login_check']))
   {
        
################################################################################################
        ##                                        Variables.                                              ##
        ################################################################################################
        
$user mysql_real_escape_string(htmlspecialchars($_POST['user']));                           ##
        
$pass mysql_real_escape_string(htmlspecialchars(md5($_POST['pass'])));                       ##
        
$query = ("SELECT password, groups FROM users WHERE user = '".$user."'");                      ##
        
$result mysql_query($query)    or die("Mysql Getting The Next Error:" mysql_error());      ##
        ################################################################################################
        
if ($row mysql_fetch_array($result))
        {
            if(
$row['password'] == $pass && $_SESSION['security_code'] == $_POST['security_code_check'] && $row['groups'] == 1)
            {
                
$_SESSION['user'] = $user;
                
$_SESSION['pass'] = $pass;
                
$_SESSION['groups'] = $_SESSION['groups'] + 1;
                
header('Location: index.php?page=Administrators');
            }
            if(
$row['password'] == $pass && $_SESSION['security_code'] == $_POST['security_code_check'] && $row['groups'] == 2)
            {
                
$_SESSION['user'] = $user;
                
$_SESSION['pass'] = $pass;
                
$_SESSION['groups'] = $_SESSION['groups'] + 2;
                
header('Location: index.php?page=Administrators_Deputys');
            }
            if(
$row['password'] == $pass && $_SESSION['security_code'] == $_POST['security_code_check'] && $row['groups'] == 3)
            {
                
$_SESSION['user'] = $user;
                
$_SESSION['pass'] = $pass;
                
$_SESSION['groups'] = $_SESSION['groups'] + 3;
                
header('Location: index.php?page=Workers');
            }
                
mysql_close($db_connection); //Closing The Db Connection.
        
}
        if(
htmlspecialchars($_POST['user']) =='' || htmlspecialchars($_POST['pass'])=='' || htmlspecialchars($_POST['security_code_check'])=='')
        {
        echo 
'אנא מלא את כל השדות';
        }
        else
        {
        echo 
'שם משתמש ואו סיסמא שגויים';
        }
    }
}
?>
תודה לעוזרים, יונתן.
__________________
יונתן.
אימייל: jonathan@zeierman.net
  Reply With Quote