Jump to content

Hashing multiple lines from a textarea


johnny042

Recommended Posts

So I have a need to generate md5 hashes for multiple lines out of a textarea.

The problem is all of the individual "\n" lines are returning incorrect md5 outputs EXCEPT for the last line (it always returns the correct md5 output)

 

Here is the code and a sample input/output test at the bottom:

 

The HTML form


<form action="hash.php" method="post">

<textarea name="hashed" rows=20 cols=41></textarea></br>
<input type="submit" value="Generate">
</form>

 

 

PHP code used to take individual \n lines and generate the individual line md5 output


$data = $_POST['hashed'] ;
foreach(explode("\n", $data) as $line) {
$hashedData = hash('md5',$line, FALSE);
echo '<strong>'. $hashedData .'</strong></br>';
}

 

 

1. You'll notice the first line (apple) generates "md5(apple + something else)" (I'm thinking the actual \n is generated as part of apple hence wrong output)

2. Same thing happens to orange

3. The third line (apple) generates the correct "md5(apple)" output

 

Sample input:

apple

orange

apple

 

Sample output:

2f9c032ecf479087117e8d6f7fe1a84f

5b3ef7abd937c92e99d740df67182c1b

1f3870be274f6c49b3e31a0c6728957f

 

 

 

Any suggestions or a possible workaround?

 

 

A few things already tried:

- using commas as a separator but it didn't work out too well :(

- tried reverse-md5'ing the wrong output but no one has yet to rainbow it

- Clean $line from enter \n spaces and %20 spaces, no dice

$clean = str_replace(' ','',$str);

Link to comment
https://forums.phpfreaks.com/topic/272878-hashing-multiple-lines-from-a-textarea/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.