<div>For a start, I'd use file_put_contents() instead of the clunky fopen() handle. </div><div><br></div><div>If you want to append the text file instead of overwriting it (as your code seems to hint at) look at this option:</div>
<div><br></div><div>// Find the passwords we already have saved</div><div>$fcontents = file_get_contents("/path/to/file.txt");</div><div><br></div><div>// Append the new password to the start of the list</div><div>
file_put_contents("/path/to/file.txt", $storedpass."\r\n".$fcontents);</div><div><br></div><div><br></div><br clear="all">Regards,<br>Michael Greenhill<br><br>Please think of the environment before printing off this email or any attachments.<br>
<br><br><div class="gmail_quote">On Tue, Nov 23, 2010 at 6:49 PM, Margaret Iaquinto <span dir="ltr"><<a href="mailto:iaquinto@ozemail.com.au">iaquinto@ozemail.com.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I used the code below and it generates an MD5 hash and stores the file OK.<br>
<br>
Trouble is - each time I enter a different 'userpass' from the form, it<br>
generates the same hash output.<br>
Why?<br>
<br>
I am just a beginner in this, so please don't use esoteric cryptography<br>
terminology. I need the veggie version.<br>
<br>
Maggie<br>
<br>
<?php<br>
/********************<br>
file: password.php<br>
called from password.html<br>
takes password from the form<br>
and<br>
encrypts it with MD5<br>
and<br>
saves it to allmysecrets.txt file<br>
******************/<br>
<br>
include('header.inc');<br>
page_header('No one will ever know');<br>
<br>
//gather the password<br>
<br>
$userpass = $_POST['userpass'];<br>
<br>
<br>
$storedpass = md5($userpass);<br>
//open the file allmysecrets.txt<br>
//use the append mode and then view it b/c I want to<br>
echo $storedpass;<br>
<br>
$fh = fopen('allmysecrets.txt', 'a');<br>
//write the encrypted password to the file<br>
fputs($fh, $storedpass."\r\n");<br>
//close the file<br>
fclose($fh);<br>
<br>
<br>
include('footer.inc');<br>
<br>
<br>
?><br>
_______________________________________________<br>
<a href="http://www.edulists.com.au" target="_blank">http://www.edulists.com.au</a> - FAQ, resources, subscribe, unsubscribe<br>
PHP Mailing List kindly supported by<br>
<a href="http://www.vcaa.vic.edu.au" target="_blank">http://www.vcaa.vic.edu.au</a> - Victorian Curriculum and Assessment Authority and<br>
<a href="http://www.vitta.org.au" target="_blank">http://www.vitta.org.au</a> - VITTA Victorian Information Technology Teachers Association Inc<br>
</blockquote></div><br>