HTTP basic auth sends credentials un-hashed and unencrypted over the wire, relying on TLS for confidentiality in transit. However, should the password be stored hashed using a standard KDF in the backend for comparison on receipt?

  • 1
    What are you trying to achieve? Why store the passwords in the first place? Sep 11, 2020 at 17:23
  • Passwords not using basic auth are also typically sent unhashed and unencrypted except for TLS. Sep 12, 2020 at 22:52

2 Answers 2


Passwords in general should be stored hashed on the server, no matter if they are transferred within some HTTP POST body as a result of a form submit or if they are transferred in the HTTP header as in Basic authentication.


Yes, it should be. The default backend for HTTP Basic Auth is htpasswd, and it encrypts passwords*:

htpasswd encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA1, or the system's crypt() routine. Files managed by htpasswd may contain a mixture of different encoding types of passwords; some user records may have bcrypt or MD5-encrypted passwords while others in the same file may have passwords encrypted with crypt().

If you're setting up an alternative backend, such as a database, then you should provide salting and hashing as strong protections against password compromise.

*Note that, per the manual, "The SHA and crypt() formats are insecure by today's standards."

  • 13
    "The default backend for HTTP Basic Auth…" - why are you assuming the OP is using Apache?
    – Bergi
    Sep 11, 2020 at 8:55
  • 2
    Nginx also defaults to recommending htpasswd in their admin guide. But you're correct that this answer skews towards the free, *nix-based alternatives that power 60% of the Internet.
    – gowenfawr
    Sep 11, 2020 at 13:11
  • @gowenfawr For a long time more than 60% of the internet didn't use HTTPS or used SSL3 and TLS1.0. "It's the default" isn't a very good argument for security - if anything it is probably a reason to be leery of it. None of the options listed by htpasswd seem up to the standards of 2020 for hashing passwords... who in their right mind would hash a password using "a version of MD5 modified for Apache"? bcrypt is the best option available and that one hasn't been state of the art for a decade.
    – Voo
    Sep 11, 2020 at 15:19
  • 4
    Reading the rest of the documentation gives me goosebumps.. "note that only the first 8 characters of the password are used to form the password. If the supplied password is longer, the extra characters will be silently discarded.".
    – Voo
    Sep 11, 2020 at 15:21
  • 2
    @Voo you're right, but what's the alternative for the average web dev? It's open source, you could always make a contribution (that also goes for myself and anyone here). Or is the answer just to modify the config and use bcrypt at 12 or 14 rounds? I don't disagree with anything you've said, but again, what's the alternative you recommend?
    – TCooper
    Sep 12, 2020 at 0:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .