You can encrypt your own passwords with the crypt() function and write the .htpasswd file in the form:
username:encrypted_passwd
username:encrypted_passwd
If you don't want to write your own encryption functions for this then you can use the Htpasswd class for php, I don't know the exact URL but you can easily do a google search for it.