Is it possible to access the username (and optionally password), currently used for HTTP authentication from Javascript code on the page?
Is it possible to access the username (and optionally password), currently used for HTTP
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit: In this answer I explain how to access a page or service via ajax that requires basic http authentication.
If you mean basic http authentication, then it should be possible (I have never tried it myself).
Basic authentication means that you add the http header
Authorizationto your request, and theXmlHttpRequestobject supports adding custom headers with the methodsetRequestHeader().The http header looks like this:
where the authentication token is constructed like this:
Javascript doesn’t have standard functions to encode to Base64, but this SO question shows you how to do that.