zero_ZX Posted September 6, 2011 Share Posted September 6, 2011 Hi, So basically this is error: if (strcmp($extuser,$username) == 0 && strcmp($extpass,$password) == 0) extpass is a value it reads from the database. That value is sha1-hashed. Password is plain and is sent via a form. So what happens is the following: extuser and username equals 0, as they match. extpass and password matches IF i put the sha1 hashed password as the password. So no problems in that, it's supposed to work that way. If we change the code a bit, so that the user shouldn't post an unknown password: if (strcmp($extuser,$username) == 0 && strcmp($extpass,sha1($password)) == 0) Right, so we take the submitted password and sha1 it. Then check if that new string matches the database and whops, login failed. Okay.. by doing some debugging by printing the actual values i conclude this: The sha1($password) equals 139a8cf8be8..... while in my database all the letters are CaSe. This is most likely the error.. Any ideas for a fix? Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/ Share on other sites More sharing options...
WebStyles Posted September 6, 2011 Share Posted September 6, 2011 Why are common hashing functions such as md5() and sha1() unsuitable for passwords? Hashing algorithms such as MD5, SHA1 and SHA256 are designed to be very fast and efficient. With modern techniques and computer equipment, it has become trivial to "brute force" the output of these algorithms, in order to determine the original input. Because of how quickly a modern computer can "reverse" these hashing algorithms, many security professionals strongly suggest against their use for password hashing. Can you post the script that was used originally to encrypt the password when it was first stored? Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/#findComment-1266194 Share on other sites More sharing options...
zero_ZX Posted September 6, 2011 Author Share Posted September 6, 2011 I'm only using this on a test basis so i just got the password from here: http://www.ratajik.com/CreateNetPassword/ I created a quick login script to check if username and the password matches with a sql query.. everything goes through just fine.. :/ The quick login script: $password2 = mysql_real_escape_string($_POST['password']); $password = sha1($password2); $username = mysql_real_escape_string($_POST['username']); $q = "SELECT * FROM `profiles` " ."WHERE `username`='$username' " ."AND `password`='$password'" Rest omitted So I find it strange that this other code wont work as expected :/ Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/#findComment-1266195 Share on other sites More sharing options...
WebStyles Posted September 6, 2011 Share Posted September 6, 2011 well there's your answer... that silly website is 'uppercassing' the result. Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/#findComment-1266198 Share on other sites More sharing options...
zero_ZX Posted September 6, 2011 Author Share Posted September 6, 2011 Okay, well I changed it.. so my debugging now shows: 139a8cf8be8e[omitted]5f53912224 139a8cf8be8e[omitted]5f53912224-1 Can any one tell me why it returns -1 and not 0 ? :S Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/#findComment-1266201 Share on other sites More sharing options...
Pikachu2000 Posted September 6, 2011 Share Posted September 6, 2011 I'm wondering if all this is really necessary. What are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/#findComment-1266206 Share on other sites More sharing options...
WebStyles Posted September 6, 2011 Share Posted September 6, 2011 add a trim to both before applying strcmp and test again. maybe there's an invisible character somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/#findComment-1266207 Share on other sites More sharing options...
voip03 Posted September 6, 2011 Share Posted September 6, 2011 zero_ZX ! Can you kindly lets know , What are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/#findComment-1266214 Share on other sites More sharing options...
zero_ZX Posted September 6, 2011 Author Share Posted September 6, 2011 Sorry guys, it was a misunderstading in my group We changed the code so it became a bit easier to read: //if (strcmp($extuser,$username) == 0 && strcmp($extpass,$password) == 0) if($extuser == $username && $extpass == sha1($password)) all works flawlessly now.. I still don't get why the other method didn't work though.. To answer your question: I was just trying to check if the usernames and passwords from one databased matched with the info from another. So, all good Quote Link to comment https://forums.phpfreaks.com/topic/246575-sha1-has-and-strcmp/#findComment-1266215 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.