ImDaveead
ImDaveead

Reputation: 321

HTTP authentication without username

I am creating a HTTP Server in node js, and I want to add a password to a page that only I will use. The Basic authentication scheme requires username and password (In the browser popup). Having a username is useless for me and I want to know if its even possible to just show a password dialog.

The current code is this, sending a Status Code 401 and the WWW-Authenticate header.

response.statusCode = 401;
response.setHeader('WWW-Authenticate', 'Basic realm="Requires Password"');
response.end();

Which creates this window in Firefox

Authentication Window

So what do I need to change in the response headers to only have a password field?

Upvotes: 6

Views: 4996

Answers (1)

cassiomolin
cassiomolin

Reputation: 131037

I want to know if its even possible to just show a password dialog.

No. The Basic authentication scheme is based on the model that the client needs to authenticate itself with a username and a password for each protection space, frequently referred as realm.

For a response with 401 and WWW-Authenticate with the value Basic, the browser will prompt for both username and password.

So what do I need to change in the response headers to only have a password field?

If, for some reason, you don't want the username, you can leave it empty, pick a default one or choose another authentication scheme that suit your needs.

Upvotes: 9

Related Questions