pappakaka Posted October 28, 2011 Share Posted October 28, 2011 I'm trying to secure my login system as much as possible from SQL injections and other attacks. I know that by using mysql_real_escape_string() you can prevent that and I'm using that on for example the username input, but I would like to know if you hash the password before you send it to the database with MD5, do you still need to use mysql_real_escape_string()? A very quick and simple example: <?php $un = $_POST['username']; $pass = $_POST['password']; $pass = md5($pass); mysql_query("SELECT * FROM users WHERE password='$pass' AND username='$un'"); ?> If someone wrote a possible SQL query in the password input, wouldn't that be rendered useless as the md5 will hash it before sending it and therefor "hide" it? Or is there any other reason you wouldn't want people to use sertain characters/symbols in their passwords? Quote Link to comment https://forums.phpfreaks.com/topic/249981-question-about-md5/ Share on other sites More sharing options...
trq Posted October 28, 2011 Share Posted October 28, 2011 You don't need to escape special chars within an md5 hash because the special chars that are harmfull wont exist in the hashed data. Quote Link to comment https://forums.phpfreaks.com/topic/249981-question-about-md5/#findComment-1282992 Share on other sites More sharing options...
pappakaka Posted October 28, 2011 Author Share Posted October 28, 2011 You don't need to escape special chars within an md5 hash because the special chars that are harmfull wont exist in the hashed data. Ok thanks, so I can basically allow the users to use whatever characters they want in thier password? Or could that possibly be harmful any other way? Quote Link to comment https://forums.phpfreaks.com/topic/249981-question-about-md5/#findComment-1282993 Share on other sites More sharing options...
ManiacDan Posted October 28, 2011 Share Posted October 28, 2011 md5 and sha1 are not suggested for password hashing anymore. The crypt() function should be used. Quote Link to comment https://forums.phpfreaks.com/topic/249981-question-about-md5/#findComment-1282997 Share on other sites More sharing options...
pappakaka Posted October 28, 2011 Author Share Posted October 28, 2011 md5 and sha1 are not suggested for password hashing anymore. The crypt() function should be used. Looked into it and it seems much better yes, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/249981-question-about-md5/#findComment-1283007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.