If you’re editing the .htaccess file for a directory on your web server to enable HTTP Basic Authentication you may need a way to generate the encrypted password that is placed in the .htpasswd file.
The Apache htpasswd utility can be used to generate the password, but an alternative method is to install and use the Node package ‘htpasswd’ (https://www.npmjs.com/package/htpasswd).
To download and run it we need Node.js and npm. Download them here if you don’t have them already, the Node installer includes Node.js and npm.
Next, install the htpasswd package by entering the following in the command prompt:
npm install -g htpasswd
Example command to generate a password:
htpasswd -nbB username password
Output to place in .htpasswd file:
username:$2a$05$R.Lk6h592WLOI7qN.xBZj.OjiJk8JECqLbYZt4vWoZHW9WLg/u1E2
You can add multiple lines to the .htpasswd file, each with a username + password combination.
Remember to place the htpasswd file in a location that isn’t fetchable by the web browser.
Here are further links on creating the htaccess and htpasswd file for 1&1 IONOS hosting users:
📝Article last updated on January 10th, 2023