I’ve just submitted a code example to Weberdev for managing .htpasswords based on work by Jarno Elonen. Read the post.htpassword manager for apache