Get support from Xavier Media
It is currently Sun Dec 08, 2013 12:27 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: no_injection(); and hidden_key();
PostPosted: Thu Sep 21, 2006 3:01 am 

Points:
See this site from pixel 2 depth looks pretty good.

heres a little snippet ill donate that I use for my Forum software to protect all SQL Injection from leaking.

PHP Code:
<?php
//copy righted Des PC Industries http://projects.nevux.info/index.html
//or PCindustries.visionstyles.info
function no_injection($string){

$string = striptags($string);
$string = htmlspecialchars($string);
$string = trim($string);
$string = stripslashes($string);
$string = mysql_real_escape_string($string);

return $string;
}

function hiddenkey($pass){
$pass = striptags($pass);
$pass = htmlspecialchars($pass);
$pass = trim($pass);
$pass = stripslashes($pass);
$pass = mysql_real_escape_string($pass);
$pass = md5($pass);

return $pass;
}
?>


Above stops sql injection and second function makes password encrpyted

example:
PHP Code:
$password = hiddenkey($password);
$username = no_injection($username);

you could also do
PHP Code:
<?php
//you must include functions for any of this to work;)
hiddenkey($_POST['password'];
no_injection($_POST['username'];
?>


Have fun


Report this post
Top
  
Reply with quote  
 Post subject: Thanks
PostPosted: Thu Sep 21, 2006 3:41 am 

Points:
Thanks for the code! 8)

People need to have SQL protection setup...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 21, 2006 10:04 pm 

Points:
Thanks for it m8! Really a good peace of code there!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 28, 2006 2:28 pm 

Points:
Not to criticize your code, but you could improve it like so:

Code:
function no_injection($string){
  $string = striptags($string);
  $string = htmlspecialchars($string);
  $string = trim($string);
  $string = stripslashes($string);
  $string = mysql_real_escape_string($string);
  return $string;
}

function hiddenkey($pass){
  $pass = no_injection($pass);
  $pass = md5($pass);
  return $pass;
}


That said, you should take additional preventative measures where possible. If you're expecting an integer (as in http://www.mysite.com/products.asp?id=45), don't merely run it through the no_injection function. Convert the variable to an integer in php before passing it to the query.

A must-read for anyone new to preventing sql injections:
http://blogs.msdn.com/ericlippert/archive/2006/11/01/how-do-i-mitigate-a-sql-injection-vuln.aspx


Report this post
Top
  
Reply with quote  
 Post subject: Clean the code
PostPosted: Thu Dec 28, 2006 5:26 pm 

Points:
Yes, just relying on that code alone will leave you open to new forms of attack. Like Ristmo said, you should check to see if the value is actually a string, char, or whatever before you try to clean it. Use some Regex to make sure it is the right type.

Then check the length of the variable so as to make sure someone didn't send a whole essay that once cleaned would still have enough ascii in it to mess you up.

finally, you can clean the code :P


Report this post
Top
  
Reply with quote  
 Post subject: Re: no_injection(); and hidden_key();
PostPosted: Fri May 01, 2009 10:09 am 
Offline
Rookie (I'm probably spamming)
Rookie (I'm probably spamming)

Joined: Fri May 01, 2009 10:02 am
Posts: 1
Points: 0
Wow.......... Thanks for the code...... I tried out.... It came out well.......


Report this post
Top
 Profile Send private message E-mail  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Registered users: No registered users


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Portal » Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[
SEO MOD © 2007 StarTrekGuide ]