[php] php MD5 generates only one hashed output

Michael Greenhill mi at whsc.vic.edu.au
Tue Nov 23 19:24:12 EST 2010


For a start, I'd use file_put_contents() instead of the clunky fopen()
handle.

If you want to append the text file instead of overwriting it (as your code
seems to hint at) look at this option:

// Find the passwords we already have saved
$fcontents = file_get_contents("/path/to/file.txt");

// Append the new password to the start of the list
file_put_contents("/path/to/file.txt", $storedpass."\r\n".$fcontents);



Regards,
Michael Greenhill

Please think of the environment before printing off this email or any
attachments.


On Tue, Nov 23, 2010 at 6:49 PM, Margaret Iaquinto
<iaquinto at ozemail.com.au>wrote:

> I used the code below and it generates an MD5 hash and stores the file OK.
>
> Trouble is - each time I enter a different 'userpass' from the form, it
> generates the same hash output.
> Why?
>
> I am just a beginner in this, so please don't use esoteric cryptography
> terminology. I need the veggie version.
>
> Maggie
>
> <?php
>     /********************
>     file: password.php
>     called from password.html
>     takes password from the form
>     and
>     encrypts it with MD5
>     and
>     saves it to  allmysecrets.txt file
>     ******************/
>
>     include('header.inc');
>     page_header('No one will ever know');
>
>     //gather the password
>
>     $userpass = $_POST['userpass'];
>
>
>     $storedpass = md5($userpass);
>     //open the file allmysecrets.txt
>     //use the append mode and then view it b/c I want to
>     echo $storedpass;
>
>     $fh = fopen('allmysecrets.txt', 'a');
>     //write the encrypted password to the file
>     fputs($fh, $storedpass."\r\n");
>     //close the file
>     fclose($fh);
>
>
>     include('footer.inc');
>
>
> ?>
> _______________________________________________
> http://www.edulists.com.au - FAQ, resources, subscribe, unsubscribe
> PHP Mailing List kindly supported by
> http://www.vcaa.vic.edu.au - Victorian Curriculum and Assessment Authority
> and
> http://www.vitta.org.au  - VITTA Victorian Information Technology Teachers
> Association Inc
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/php/attachments/20101123/fea596a3/attachment.html 


More information about the php mailing list