damianjames Posted July 29, 2008 Share Posted July 29, 2008 Hi all - I'm trying to parse the contents of a text/csv file, change the second column to an md5 hash of it's original value, then re-save the file. I'll be using it to change a clear text user/pass list to md5 hashed passwords, then do a SQL load of the data as part of a user import. I studied a pre-made script and tried to write my own that followed it. I rewrote the script I looked at to not use a salt. My code for processing the file is as follows: <?php $password = file('password.txt'); foreach($password as $key => $pass) { $line = explode(",", $pass); $line[1] = md5($line[1]); $password[$key] = implode(",", $line); } $password = implode("\r\n", $password); file_put_contents('password.txt', $password); echo "File output complete"; ?> The contents of the testing file are: damian,12345 damian1,67891 The contents of the processed file are: damian,e6481c46e064c35e8f6e371d72912507 damian1,7743900015b6b880f6c937b10780acc2 The first login fails. I checked an md5 web site that allows you to enter values and generate a hash from them, and the processed file with the md5 hash -should- look like: damian,827ccb0eea8a706c4c34a16891f84e7b damian1,7743900015b6b880f6c937b10780acc2 I'm a little stumped. I was thinking if I got the implodes incorrect or something, that both lines would be incorrect, but only the first one is. Thank you all for the help! Quote Link to comment Share on other sites More sharing options...
btherl Posted July 29, 2008 Share Posted July 29, 2008 Try calling trim() on your password value to remove any newline at the end. To check for such invisible characters you can do print urlencode($line[1]) . "<br>"; A hidden character such as newline will show up url encoded, like "%0a" Quote Link to comment Share on other sites More sharing options...
damianjames Posted July 29, 2008 Author Share Posted July 29, 2008 $line[1] = md5(trim($line[1])); Worked like a champ. Thanks for your help! Quote Link to comment 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.