I am running a Perl application named bitlfu.For login it is using something like Apache HTTP Basic Auth but not a form.I want to make form for the login with username and password field. I have tried JavaScript and PHP with no results till now.
So I need help!
PS: this kind of url works
http://user:password@host.com
You can redirect the user to
http://user:password@host.com
with Perl, or using JavaScript. I don't know Perl so I'll show you the JS:This should work. The only problem is that this shows the password in the URL.
The awesome AJAX way using jQuery:
The ultimate Perl way (I think)
The method of explicitly redirecting
document.location
with username@password in URL caused me some problems with Safari giving a phishing warning.If I instead first make an AJAX request to a URL with basic auth headers added, and then redirect document.location without the username/pass in the URL then it worked better for me
Example
Unfortunate caveat with Safari only, if you type your username and password incorrectly, then it makes another standard HTTP basic auth popup, but this is better than a big red "Phishing warning" that occurs when you make the document.location include username/pass
Chrome doesn't have duplicate popup if login credentials are incorrect though
I think a simple JavaScript like:
should do the work.
So basically, you have to create a form, with a user and pass field, then onsubmit, use the part of JavaScript given here:
where $() is a document.getElementById or jquery or so. I used the $() function to make the code shorter. Here is an implementation, which does not work on every browser. Again, look throw jQuery for cross browser solution.
Otherwise, you can use php and redirect the user with a header location.
php way:
This is a simple plug&play solution ;-). Will work for any domain (and on HTTPS too):
You can drop this in your 401 error document.
Note that
return false
is required so that the page is not reloaded twice.