Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for existing record? 1

Status
Not open for further replies.

cleansedbb

Technical User
Feb 11, 2002
95
US
I have several text files. (and unfortunatly they need to be text instead of mysql)

the data is

Username1:MD5CryptedPassword
Username2:MD5CryptedPassword
Username3:MD5CryptedPassword
Username4:MD5CryptedPassword

I have an existing script that inserts by appending the
username and password at the bottom of these files. thing
is I've noticed no one bothered with a existing record
check.

How can i read in say "users.passwds" and check for
username2 before adding username2? and if it's there
error out with a message?


existing code:
filepath1-5 (since there are 5 files)
i.e. filepath1

$md = crypt($password);
$passwd = "$login:$md" . "\n";
$filepath1 = fopen($filepath1, "a") or die("Couldn't open PASSWD FILE for writing!");
fwrite($filepath1, $passwd);
fclose($filepath1);


TIA

 
The tricky part is not checking for an existing record. Before writing, you just read through all the records, looking for an existing username.

The tricy part is doing something about it if you find an existing record -- and there would be no point in checking if you're not going to do something about it.

In cases like this, you might read the entire old file and copy the records into a new one. Then append the record for the user that has changed his password, then delete the old file and rename the new file to the old name.

The really tricky part is using file locks (and checking for them, too, before manipulating files) to make sure you don't have collisions on your file writes.

Want the best answers? Ask the best questions: TANSTAAFL!
 
sounds like fun, i'll give it a shot. played a little with flocks and the password updates is a good possibility.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top