How to secure my web

Reply

Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

How to secure my web

 
0
  #1
Aug 16th, 2009
I`ve finished my website,its a social netwrk web in PHP.
Now before i lunch it,i would like to know what are the precautions i should take to protect it from hackers.
please if any one has idea on what i should do,to protect mysql,and my site as a whole.i will be greatefull if u`ll leave me ur suggestions.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 281
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

Re: How to secure my web

 
0
  #2
Aug 16th, 2009
mysql_real_escape_string()
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 173
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 13
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: How to secure my web

 
0
  #3
Aug 16th, 2009
Well for one, I would use mysql_real_escape() on any variable you are passing to MySQL. That should prevent any kind of MySQL injection. I would make sure that your passwords are hashed correctly (using md5() or sha1() ). For added security I would salt your encryptions. See this page for more on salts. Beyond that: Don't store password in cookies (using a unique id or some kind of session id), don't allow code tags (such as <script>) in any kind of use input that will be placed on a page, and be sure that users are authenticated on every page. If you would like, you could give us the address of your site and we can look at some possible security flaws.
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: How to secure my web

 
0
  #4
Aug 18th, 2009
thankx guys for replying))
i added the following in my login form.
  1. $user=mysql_real_escape_string($_POST['user']);
  2. $password=mysql_real_escape_string(md5($_POST['password']));
when i try to login in my localhost it works fine.but in server online it doesn`t work.
When i used addslashes instead of mysql_real_escape_string,the function worked in all sectors.
So what is the difference between these two functions,And if iwant to use mysql_real_escape_string how should i make it to work.??
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 173
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 13
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: How to secure my web

 
0
  #5
Aug 18th, 2009
Well this is definitely an improvement! I believe you problem lies in the fact that the passwords in the database aren't hashed using md5(). You need to create a temporary PHP file on your site with just one line of code:
  1. echo md5("password here");
Then all you have to do is go through you your databases passwords and plug them into the md5 function. After that just replace the old password with the new hashed string. (It is important to make sure that the row that holds passwords can handle a hash. If it is a Varchar it needs to be at least 32 in length). Next, you might need to know if your host has magic_quotes_gpc on (Chances are your host has it on). If so, on the server you will need to change the code so that before you mysql_real_escape_string() a string that you pass it through stripslashes:
  1. $user = mysql_real_escape_string(stripslashes($_POST['user']));
  2. $password = mysql_real_escape_string(stripslashes($_POST['password']));
The reason for this is that when magic_quotes_gpc is on, most strings will automatically be escaped already (but not escaped for MySQL!). You will need to use [code]stripslashes()[/icode] before you use any MySQL escaping functions on it, so that the string is unescaped. This may sound confusing (In fact, it's been deprecated in PHP 5.3 and will be removed in PHP 6), but I believe this could be your solution.
Last edited by FlashCreations; Aug 18th, 2009 at 3:47 pm.
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: How to secure my web

 
0
  #6
Aug 18th, 2009
@FlashCreations,in da web when registering i hash the passwords with md5().thats why when login i was using
  1. $user=$_POST['user'];
  2. $password=md5($_POST['password']);
the problem started after i added
  1. mysql_real_escape_string
and how will i know if the magic_quotes_gpc is ON??
also i tested sending comments using
mysql_real_escape_string it worked.
it seems the problem is in the Authorization.
help me in this plz
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 173
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 13
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: How to secure my web

 
0
  #7
Aug 18th, 2009
You will know if magic_quotes_gpc is on by asking your host (If they have the latest version of PHP it shouldn't be!). That might not be it. The only way for us to help you is if you post your code.
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: How to secure my web

 
0
  #8
Aug 19th, 2009
here is my login code
  1. <?php session_start();
  2.  
  3. $user=mysql_real_escape_string($_POST['user']);
  4. $password=mysql_real_escape_string(md5($_POST['password']));
  5.  
  6.  
  7. //connecting to databases
  8. include"config.php";
  9.  
  10.  
  11.  
  12. $query = "SELECT *FROM login where (user='$user' and password='$password')" ;
  13. $result=mysql_query($query);
  14. if(mysql_num_rows($result)==1) {
  15.  
  16. $row=mysql_fetch_array($result);
  17. $id=$row['id'];
  18. $user=$row['user'];
  19. $password=$row['password'];
  20. $email=$row['email'];
  21.  
  22. $_SESSION['id']=$row['id'];
  23. $_SESSION['user']=$row['user'];
  24. $_SESSION['password']=$row['password'];
  25. $_SESSION['email']=$row['email'];
  26. $_SESSION['name']=$row['name'];
  27. $_SESSION['photo']=$row['photo'];
  28.  
  29. include "index.php";
  30.  
  31.  
  32. }else{
  33. include"wronglogin.php";
  34. }
  35.  
  36. ?>
]
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 281
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

Re: How to secure my web

 
0
  #9
Aug 19th, 2009
yes that is also a corect statement but u also need to do this for the registration as well because it is actually inserting into the database there is more of a risk
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 254
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: How to secure my web

 
0
  #10
Aug 19th, 2009
Your code is looking fine. Do you have any issue?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC