Hi,
I have a text file including usernames and passwords in each lines like below:
username1
pass1
username2
pass2
I want users change their passwords via a form. It is ok to go to the line which user's password is included. However when i write to the line using fwrite function, if the user's new pass is longer than previous pass, it overwrites the next line(next user's username line).
Here is the code;
$fp = fopen($file, 'r+');
while ( !feof($fp) ) {
$line = fgets($fp,1024);
$u_name = "username1";
$Find = ereg($u_name, $line, $Array);
if ( ($Find > 0) && ($Array[0]==$Find)) {
$new_pass = "passsssssssss";
fwrite($fp, $new_pass);
echo "ok dude.
";
break;
}
}
fclose($fp);
After runngin this code, text files becomes like this:
username1
passs
ssssssme2 <-- Note here.
pass2
So how can i prevent overwriting the following line. Thanks for replies.
Comments
If you are saving them in a database, you are a lot safer but since it is a standard textfile ANYONE could find it and see those passwords.
And besides, i don't care who you are, you have no right looking at your user's passwords.
I'm going to write you a better script..
Okay... took awhile but here is the URL:
http://s94621642.onlinehome.us/examples/example1.php
You can check the source code here:
http://s94621642.onlinehome.us/examples/example1source.txt
[b][blue]Snoochie Boochies[/blue][/b]