Jump to content

[SOLVED] Stuck on md5 script updating text file


damianjames

Recommended Posts

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!

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.