Not a member yet? Register for your free account!

 

Go Back   elitepvpers > 2Moons / Dekaron > 2Moons PServer Hosting

 

[RELEASE] Simple login Script (with anti SQL inject)

This is a discussion on [RELEASE] Simple login Script (with anti SQL inject) within the 2Moons PServer Hosting forum part of the 2Moons / Dekaron category; Just a simple login script, nothing fancy about it, but added with Anti SQL inject ! PHP Code: <?php // Edit your mssql info here ...

Reply
 
LinkBack Thread Tools
Old 02-08-2010, 10:57   #1
I post too much
 
janvier123's Avatar
 
Join Date: Nov 2007
Posts: 1,840
Received Thanks: 868
[RELEASE] Simple login Script (with anti SQL inject)

Just a simple login script, nothing fancy about it,
but added with Anti SQL inject !

PHP Code:
<?php

// Edit your mssql info here
// BEGIN MSSQL INFO
$CONFIG['host'] = "localhost";
$CONFIG['user'] = "sa";
$CONFIG['pass'] = "server";
// END MSSQL INFO

//----------------------------- DO NOT EDIT ANYTHING BELOW HERE !!!!! ------------------------------------

$CONFIG['conn']  = mssql_connect$CONFIG['host'], $CONFIG['user'], $CONFIG['pass']);

function 
anti_injection($sql) {
   
$sql preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$sql);
   
$sql trim($sql);
   
$sql strip_tags($sql);
   
$sql addslashes($sql);
   return 
$sql;
}
//----------------------------------------------------------------------------------------------------------

if(isset($_GET['action']) && ($_GET['action'] == "login")){

    
$user anti_injection($_POST['user']);
    
$pass anti_injection($_POST['pass']);
    
$crypt_pass md5($pass);
        
    
$result1 mssql_query("SELECT * FROM account.dbo.user_profile WHERE user_id = '".$user."'"); 
    
$count1 mssql_num_rows($result1); 

    
$result2 mssql_query("SELECT user_pwd FROM account.dbo.user_profile WHERE user_id = '".$user."'"); 
    
$row2 mssql_fetch_row($result2); 

    if(
$count1 == '0') {
        echo 
'<br>This game account is not found in the database.';
    }
    elseif(
$row2[0] != $crypt_pass) {
        echo 
'<br>Wrong password. Try again.';
    }
    elseif(
$_GET['login'] != 'login' && $count1 == '0') {
        echo 
'<br>Login Error, Please login again.';
    } else {
    
    
// Begin secure content 
        
$_SESSION['user'] = $user;
        echo 
"<h3>Welcome, ".$_SESSION['user']."</h3>";
        echo 
"<br>";
        echo 
"Your content here";
    
// Dont forget to and your session
    // session_destroy();
    // End secure content
    
}
} else {
  
echo 
'<h2>Login here</h2><br /> 
    <form name="" action="'
.$_SERVER['php_self'].'?action=login" method="post"> 
        Name: <input type="text" name="user" maxlength="16"><br /> 
        Password: <input type="password" name="pass" maxlength="16"> <br />
        <input type="submit" value="Login!"> 
    </form>'
;
}
?>
if you got a error, please reply with a error code
have fun !
@Mod this is not a double topic, its 2 different scripts so ... to prevent any confusion
@Everyone THIS IS MADE FOR DEKARON SO IAM POSTING IN THE RIGHT SECTION


Last edited by janvier123; 02-08-2010 at 11:26.
janvier123 is offline  
The Following 2 Users Say Thank You to janvier123 For This Useful Post:
Darth Nerd (02-08-2010), maleket-el-oloob (02-08-2010)
Old 02-08-2010, 12:00   #2
Senior Member
 
gedimazs's Avatar
 
Join Date: May 2008
Posts: 538
Received Thanks: 89
you can make reg page with anti SQL injection
gedimazs is online now  
Old 02-08-2010, 12:06   #3
I post too much
 
janvier123's Avatar
 
Join Date: Nov 2007
Posts: 1,840
Received Thanks: 868
sure

EDIT: [Only registered and activated users can see links. ]
tested and working

Last edited by janvier123; 02-08-2010 at 12:31.
janvier123 is offline  
The Following 2 Users Say Thank You to janvier123 For This Useful Post:
gedimazs (02-08-2010), maleket-el-oloob (02-08-2010)
Reply

Thread Tools




All times are GMT +2. The time now is 11:22.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0