rockinaway Posted April 3, 2008 Share Posted April 3, 2008 Which type should I use for my passwords? Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/ Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 I use crypt()...but I don't know which is better Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-508748 Share on other sites More sharing options...
discomatt Posted April 3, 2008 Share Posted April 3, 2008 SHA1 has less collisions, and rainbow tables aren't quite as complete. Â As long as you salt properly, both work very well. I would personally use SHA1, if the increased bitlength isn't an issue. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-508758 Share on other sites More sharing options...
Daniel0 Posted April 3, 2008 Share Posted April 3, 2008 I'd probably go with something like sha-256: Â hash('sha256', $string); Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-508796 Share on other sites More sharing options...
rockinaway Posted April 4, 2008 Author Share Posted April 4, 2008 I didn't know sha256 was possible :S Â Â And what do you mean by salting properly? Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509322 Share on other sites More sharing options...
conker87 Posted April 4, 2008 Share Posted April 4, 2008 Have some randon string before or after the string password, ex: Â <?php $password = sha1(rand(0,1000) . $password); ?> Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509324 Share on other sites More sharing options...
haku Posted April 4, 2008 Share Posted April 4, 2008 I didn't know sha-256 was possible either. Â crypt() isn't so good, as it can be decrypted. sha1 and md5 are both one-way, making them more secure. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509325 Share on other sites More sharing options...
rhodesa Posted April 4, 2008 Share Posted April 4, 2008 How can crypt() be decrypted? Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509349 Share on other sites More sharing options...
maexus Posted April 4, 2008 Share Posted April 4, 2008 Have some randon string before or after the string password, ex: Â <?php $password = sha1(rand(0,1000) . $password); ?> Â This is what I don't understand. If you have a completely random salt, how do you compare user input of a password string later on? I could understand if the salt is constant, then it could be added after the input is submitted but if the salt is random, there is no way of doing a comparison. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509354 Share on other sites More sharing options...
drisate Posted April 4, 2008 Share Posted April 4, 2008 Just use <?php $password=md5(md5($_POST[password])); if ($password==$pass_in_db){ echo "The pass is teh same"; }else{ echo "The pass is not the same"; } ?> Â Double MD5 is perfect :-) Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509361 Share on other sites More sharing options...
rhodesa Posted April 4, 2008 Share Posted April 4, 2008 You can't just concatenate a random string to the front. Salts are used with crypt(). The salt is added to the front of the encrypted version. So, you use the encrypted version to check...like so:  <?php  //How to encrypt it  //Crypt will add a random salt for you  //Every time you run crypt, it will return something different (unless you specify the salt)  $encrypted = crypt($password);  //How to check it  if(!strcmp($encrypted,crypt($password,$encrypted)))   print 'Success';  else   print 'Fail'; ?>    Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509392 Share on other sites More sharing options...
drewbee Posted April 4, 2008 Share Posted April 4, 2008 Yeah the random string attached is rather pointless, as it would have to be consistent. if there password is asdf, and we make it 123123_asdf. The next time a hacker tries to access the system it is required of you to use the same salt it would still have to be using 123123_$password. It is a rather moot use. Â I'm not to sure the double md5 helps either. If someone is trying to brute the password, in order for your system to find a match you need it to double md5 the input. the same word md5'ed twice still has the same outcome. This would however help prevent lookup attacks if the user already compromised the database and can see the encrypted password. This is when double md5'ing would be useful. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509401 Share on other sites More sharing options...
Daniel0 Posted April 4, 2008 Share Posted April 4, 2008 Yeah the random string attached is rather pointless, as it would have to be consistent. if there password is asdf, and we make it 123123_asdf. The next time a hacker tries to access the system it is required of you to use the same salt it would still have to be using 123123_$password. It is a rather moot use. Â You're supposed to keep the salt secret. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509413 Share on other sites More sharing options...
drewbee Posted April 4, 2008 Share Posted April 4, 2008 You're supposed to keep the salt secret. Â Yes; but my point is lets say the user creates a password 'password'. Â Programtically we salt 123_ onto the beginning of it and we get 123_password, then encrypt it, and end up with our 32 bit password that we store in the database. Â If someone tries to brute force it and they enter 'password' into the box when trying to log on as a user, we have to progmatically attach '123_' to the beginning of what they entered so that the encryption will match up. Â The only place i see a salt being useful is if the database has already been compromised, and the breacher can see the encrypted password. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509429 Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 Yes, of course -any salting does not prevent brute force attacks. However, if someone is going to try and brute force though your system that adds the salt, then its going to take a hell of a long time. Sure, writing a program to brute force may not - but adding in the requests to an external server will. Â As for the idea of using the MD5 algorithm twice - i occassionaly see it mentioned that this is infact less secure than a single use of the MD5. I think this tends to be talked about with reference to hash collisions. That said, i've never seen anything which proves this or otherwise - and it certainly seems counter intuitive to me. Anyone have any thoughts on that? Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509431 Share on other sites More sharing options...
Daniel0 Posted April 4, 2008 Share Posted April 4, 2008 You're supposed to keep the salt secret. Â Yes; but my point is lets say the user creates a password 'password'. Â Programtically we salt 123_ onto the beginning of it and we get 123_password, then encrypt it, and end up with our 32 bit password that we store in the database. Â If someone tries to brute force it and they enter 'password' into the box when trying to log on as a user, we have to progmatically attach '123_' to the beginning of what they entered so that the encryption will match up. Â The only place i see a salt being useful is if the database has already been compromised, and the breacher can see the encrypted password. Â I don't think you understand salting. It's supposed to protect brute forcing if you have the hash. If you add, say a 30 char long salt to the beginning, then nobody will have enough computational power to brute force within their life span (as long as the salt remains secret). To protect your login form, just restrict the number of failed login attempts and block the account for a fixed amount of time. Then it'll take a long time to brute force through your login form as well. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509443 Share on other sites More sharing options...
rockinaway Posted April 4, 2008 Author Share Posted April 4, 2008 As currently I am just using the md5() hash, that is what I have always used. But I was just reading up on it and then sha-1 turned up. Â I don't think md5'ing several times has any point to it, it will just keep doing the same thing again and again, and could prove worse? Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509506 Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 The point of using the md5() hash twice is the same as salting - if someone has the hash, then brute force is harder and rainbow tables are useless. As I mentioned earlier however, there appears to be some debate as to wether it's a good idea. I'd recommend adding a salt anyway. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509509 Share on other sites More sharing options...
rockinaway Posted April 4, 2008 Author Share Posted April 4, 2008 Even with an md5 I should add a salt? Could this salt be anything? Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509511 Share on other sites More sharing options...
GingerRobot Posted April 4, 2008 Share Posted April 4, 2008 Yes. It's best you make the salt of a reasonable length and of mixed characters. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509518 Share on other sites More sharing options...
rockinaway Posted April 4, 2008 Author Share Posted April 4, 2008 So this salt would be the same for every password hashed? Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509521 Share on other sites More sharing options...
Daniel0 Posted April 4, 2008 Share Posted April 4, 2008 So this salt would be the same for every password hashed? Â It could be, but it could also be generated dynamically. You'll just have to ensure that it's always the same for the same password, otherwise you cannot compare it again when a user enters a password. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509537 Share on other sites More sharing options...
haku Posted April 5, 2008 Share Posted April 5, 2008 How can crypt() be decrypted? Â My bad. I thought I had read of decrypt(), but I had actually read of mcrypt_decrypt(). crypt() is one way. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509740 Share on other sites More sharing options...
drisate Posted April 5, 2008 Share Posted April 5, 2008 I don't think double MD5 can cause any problem at all ...  123 to 202cb962ac59075b964b07152d234b70 202cb962ac59075b964b07152d234b70 to d9b1d7db4cd6e70935368a1efb10e377  Good luck cracking that ... hehe  Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509751 Share on other sites More sharing options...
Daniel0 Posted April 5, 2008 Share Posted April 5, 2008 I don't think double MD5 can cause any problem at all ...  123 to 202cb962ac59075b964b07152d234b70 202cb962ac59075b964b07152d234b70 to d9b1d7db4cd6e70935368a1efb10e377  Good luck cracking that ... hehe  That's really poor encryption. The idea is about string length. Longer strings take longer time to crack. Seeing as a brute-force searching algorithm would run at O(n!), if there is a fairly long salt at the front of the actual password in the hash, cracking the password within reasonable time would be impossible. When brute-forcing your string one would just do md5(md5($string)); instead of md5($string);. Quote Link to comment https://forums.phpfreaks.com/topic/99421-md5-or-sha-1/#findComment-509843 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.