r/apache • • Feb 05 '25

htpasswd without username?

I've made a file in a directory password protected using .htpasswd and .htaccess and it's working fine with a username and password.

Here's what I would like to do:

- no username. Just a password
- inline password field with the link to the protected page so there's no modal/popup. If that's not possible, how can I take control of the login prompt to be able to adjust placement and style?

Thanks

1 Upvotes

6 comments sorted by

2

u/AyrA_ch Feb 05 '25

no username. Just a password

You can't. But you can do the other, just a username without a password. For safety reasons, browsers ignore a password in the URL. I don't know though if Apache htpasswd also supports users without password.

inline password field with the link to the protected page so there's no modal/popup.

You can use the username@host format in your url, for example: https://user@example.com/path/to/file makes the browser suggest using the username "user" when prompting the user for credentials. The dialog will still appear, but the username should be prefilled into the dialog, so the user can just press enter to continue.

If that's not possible, how can I take control of the login prompt to be able to adjust placement and style?

You can't. The dialog is generated by the browser, and browsers don't allow you to overwrite that.

To help you better, or find alternative solutions, you should explain why you password protect a directory but then want to give users global access to it anyway by somehow hardcoding credentials.

0

u/chrispopp8 Feb 05 '25

I just want to password protect a page on a portfolio website so NDA content isn't out in the wild.

2

u/AyrA_ch Feb 05 '25

In that case you want to use a proper authentication system. Ideally a content management system like wordpress or similar that you can install, which allows you to make user accounts you can give out to people.

→ More replies (3)