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);

Edited by johnny042
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.