To create .htpasswd file with an encrypted password, use the htpasswd command in a shell:
htpasswd .htpasswd username
The contents of .htaccess can be something like:
AuthUserFile /path/to/dir/.htpasswd AuthName "Members Only" AuthType Basic Require valid-user
The AuthUserFile path must be absolute, relative path doesn't work.