TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-10-2009, 07:13 PM   #1 (permalink)
The Visitor
 
Join Date: Jan 2009
Location: Netherlands
Posts: 3
Thanks: 0
Bram is on a distinguished road
Default encryption and security

Well, I have a bunch of questions to ask, but I will start with this one.

When I read tutorials, articles or topics on the internet about security I often read the following thing:

Code:
<?php 
 
   // escape all data in variables to prevent mysql injection   
  $user = mysql_real_escape_string($user);
  $pass = mysql_real_escape_string($pass);
  $pass = md5($pass);
?>
Now my question, is it really necessary to use the mysql_real_escape_string() function when you will md5() or sha1() the password? Because I always thought you use the mysql_real_escape_string() function to escape special characters into a string by using '\'. But when you use md5() or sha1(), the password itself would be completely encrypted so you wouldn't have to use the mysql_real_escape_string() function?

The code would then become like this:

Code:
<?php
   $user=mysql_real_escape_string($user);
   $pass=md5($pass);
?>
Well I hope you understand my question, since my english isn't perfect but I'm working on it. Thanks!
Bram is offline  
Reply With Quote
Old 02-10-2009, 07:37 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Yes, you're right. The MD5 function will return a string only ever containing 32 hexadecimal (0-9a-f) characters so there's no need to escape that.
Salathe is offline  
Reply With Quote
Old 02-10-2009, 07:42 PM   #3 (permalink)
The Visitor
 
Join Date: Jan 2009
Location: Netherlands
Posts: 3
Thanks: 0
Bram is on a distinguished road
Default

Thank you, I just wanted to know sure.
Bram is offline  
Reply With Quote
Old 02-11-2009, 12:03 AM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Although that is correct and there are no security implications in such code, you must remain consistent if you're not going to escape passwords. Take the following as a key example as to why you must remain consistent in either escaping or not escaping:

php Code:
$szString = "'Test'";
echo md5($szString);
echo "\n";
echo md5(mysql_real_escape_string($szString));

As you can see, the two MD5 strings now differ because the former has no slashes, and the latter has slashes to escape the single quotes.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loggining ( password and encryption ) Orc General 9 02-09-2008 08:24 AM


All times are GMT. The time now is 12:59 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design