Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

RE: [PHP3] .htpasswd From: Z.Nijmeyers <email protected>
Date: 03/05/99

two things

original post(bottom):
using crypt() without a salt results in different outcomes everytime
doesn't it?
what good is that?

answer(top):
can someone point me to information about semaphores?
don't know what the hell they are

At 20:05 5-3-99 , you wrote:
>Sorry to step in here, but it should be noted that this method, while
>much better than nothing, still does not eliminate the possibility of
>concurrent
>attempts to write... After all, what if two processes at the same time, look
>for the lock file,
>it doesnt exist yet, so both processes attempt to create a lock file and
>then happily
>attempt to modify your file. Semaphores are the only complete way of
>eliminating this problem.

>-----Original Message-----
>From: Cameron Just [mailto:ccjust <email protected>]
>Sent: Thursday, March 04, 1999 10:31 PM
>To: Matthew Joseff
>Cc: php3 <email protected>
>Subject: Re: [PHP3] .htpasswd
>Heres some code we just wrote which adds users to a htpasswd file.
>1. Creates a temp file called $htpasswdfile.".lock"
>2. If this file exists then it waits until doesn't(This stops the
>occurrence of two people adding at once)
>3. It reads in an existing htpasswd file and dumps contents into and array.
>4. Makes sure the new username doesn't already exist.(If it does removes
>lock file and exits.)
>5. Generates the new username password combination and tacks it onto the
>end.
>6. Writes the new htpasswd file.
>7. Removes Lock file.
>
>The Lock file never gets written to it's just there to let other processes
>know that the htpasswd file is currently being modified.
>This could be done using semaphores but we didn't want to re-learn them
>just yet :)
>You could also write other functions to delete and modify users using the
>same principles.
>
>VARIABLES USED
>.............................
>$username
>$password
>$htpasswdfile
>............................
>
>function useradd($username,$password) {
>global $htpasswdfile;
>
> while (file_exists($htpasswdfile.".lock")) {
> sleep(1);
> clearstatcache();
> }
>
> symlink($htpasswdfile,$htpasswdfile.".lock");
> $userfile = file($htpasswdfile);
>
> for ($i=0;$i<count($userfile);$i++) {
> $uppairs[] = explode(":",$userfile[$i]);
> $uppairs[$i][1] = trim($uppairs[$i][1]);
> if ($uppairs[$i][0] == $username) {
> unlink($htpasswdfile.".lock");
> return -1;
> }
> }
> $uoutfile .= $username.":".crypt($password)."\n";
>
> $ufp = fopen($htpasswdfile,"a");
> fputs($ufp,$uoutfile);
> fclose($ufp);
> unlink($htpasswdfile.".lock");
>}
dag

tinusz.

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3
List administrator:  zeev-list-admin <email protected>