Modify theese routines to fit your needs
function updateUser( $Username, $newPwd )
{
$newPwd = crypt( trim( $newPwd) );
$theFile = file( ".htpasswd" );
$UpdatedUsers = array();
while( list( $LineNr, $Line ) = each( $theFile ) )
{
list( $usr, $pwd ) = explode( ":", $Line );
if( $Username == $usr )
{
$UpdatedUsers[ $usr ] = $newPwd;
}
else
{
$UpdatedUsers[ $usr ] = $pwd;
}
}
if( !$fp = fopen( ".htpasswd", "w" ) )
{
echo "Couldn't open passwdfile";
exit;
}
while( list( $usr, $pwd ) = each( $UpdatedUsers ) )
{
fputs( $fp, "$usr:$pwd" );
}
fclose( $fp );
}
function deleteUser( $Username )
{
$theFile = file( ".htpasswd" );
while( list( $LineNr, $Line ) = each( $theFile ) )
{
list( $usr, $pwd ) = explode( ":", $Line );
if( $Username != $usr )
{
$NewUsers[ $usr ] = $pwd;
}
}
if( !$fp = fopen( ".htpasswd", "w" ) )
{
echo "Couldn't open passwdfile";
exit;
}
while( list( $usr, $pwd ) = each( $NewUsers ) )
{
fputs( $fp, "$usr:$pwd" );
}
fclose( $fp );
}
function addUser( $newUsr, $newPwd )
{
$newPwd = crypt( trim( $newPwd) );
$newUsr = trim( $newUsr );
if( !$fp = fopen( ".htpasswd", "a+" ) )
{
echo "Couldn't open passwdfile";
exit;
}
fputs( $fp, "\n$newUsr:$newPwd" );
fclose( $fp );
}