You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Gunter Sammet <Gu...@SammySolutions.com> on 2002/09/04 01:13:30 UTC

[users@httpd] delete user in htpasswds through php

Hello all:
Did a bit of reading and couldn't find an answer which makes me happy.

If I need to remove a user from an htpasswd file, do I really need to read
the whole file in, remove the user through code and write it again. Isn't
there an easier way? Everything I found on Google pointed into this
direction.

Would love to hear if there is an easier way!?
TIA
Gunter


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] delete user in htpasswds through php

Posted by Gunter Sammet <Gu...@SammySolutions.com>.
<snip>
As has been mentioned: I'm SURE there's a PHP support place for this,
this list is for the Apache HTTPD server.
</snip>

Thanks for this and all other answers. The reason I posted is not to get php
code or support. I just wanted to ensure that a new htpasswd.exe hasn't
slipped through my cracks and the one I am using is still up to date.
Thanks for your answers. I think I will have to do it the harder way.
G.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] delete user in htpasswds through php

Posted by Chris Taylor <ch...@x-bb.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

No, not AFAIK, but it's relatively easy.

Read file into array (split by line), delete line which you don't
like. Output array over the top of old file. :)

As has been mentioned: I'm SURE there's a PHP support place for this,
this list is for the Apache HTTPD server.

Chris Taylor - The guy with the PS2 WebServer
Email: chris@x-bb.org - PGP: http://www.x-bb.org/chris.asc

- ----- Original Message ----- 
From: "Gunter Sammet" <Gu...@SammySolutions.com>
To: "Apache Users" <us...@httpd.apache.org>
Sent: Wednesday, September 04, 2002 12:13 AM
Subject: [users@httpd] delete user in htpasswds through php


> Hello all:
> Did a bit of reading and couldn't find an answer which makes me
> happy.  
> 
> If I need to remove a user from an htpasswd file, do I really need
> to read the whole file in, remove the user through code and write
> it again. Isn't there an easier way? Everything I found on Google
> pointed into this direction.
> 
> Would love to hear if there is an easier way!?
> TIA
> Gunter
> 
> 
> --------------------------------------------------------------------
> - The official User-To-User support forum of the Apache HTTP Server
> Project. See <URL:http://httpd.apache.org/userslist.html> for more
> info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPXVDciqf8lmE2RZkEQKJQwCfX3ooef+tX8GSIcn+reigUATxjlIAnjO4
bE5RAiS9wP58et+bDU+2K93C
=oj2D
-----END PGP SIGNATURE-----



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] delete user in htpasswds through php

Posted by Michael <mi...@asstr.org>.
	1) I'm assuming that just opening the file in vi and removing the user won't do what you want :) (that is, you want this to be an automated process).

	Editing any pure test file is going to require you to read the
entire file in, truncate it, and write it back - text files are
a relatively primitive way to store things, when it comes right
down to it. It's not all that "hard" to do, though - the code
in perl, for instance, is short and easy:

use IO::Seekable;
use Fcntl ':flock';

# open and lock the file
open FILE, "+<htpasswd";
flock FILE, LOCK_EX;
$in = join( '', <FILE> );

# remove the username in question
$in =~ s/^$username:.*\n//m;

# since we made the file shorter, we have to truncate it
truncate FILE, 0;
seek FILE, 0, SEEK_SET;

# write out the new file and close it
print FILE $in;
flock FILE, LOCK_UN;
close FILE;

	Note that this code's main failing is that it reads the entire
htpasswd file into memory. If this is a performance issue for you then I
*strongly* suggest that you switch to using dbm or sql-based passwords,
since the overhead of reading that text file is hurting apache, too :-)
The flat htpasswd file is good for small amounts of users, but if you've
got more than a few then def. go for a dbm (hash) file or sql db.
This will make removing an entry easier for you, too - there are dbm
libraries for perl, C, and probably lots of other languages....

- Michael


On Tue, 3 Sep 2002, Gunter Sammet wrote:

> Hello all:
> Did a bit of reading and couldn't find an answer which makes me happy.
>
> If I need to remove a user from an htpasswd file, do I really need to read
> the whole file in, remove the user through code and write it again. Isn't
> there an easier way? Everything I found on Google pointed into this
> direction.
>
> Would love to hear if there is an easier way!?
> TIA
> Gunter
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org