How can I password protect a basic HTML page?

安稳与你 提交于 2019-12-02 06:32:29

问题


What is the simplest possible form of password protection I can use, that doesn't need to be super secure, just keep out the riffraff? It ideally can be tacked onto a website made of HTML and javascript.

It also needs to work in all browsers (can't rightly allow users to just switch browsers so they can access the contents of the password-protected site!)

Javascript's prompt function seems to be filtered out by IE, so that is out of the question.


回答1:


Use HTTP basic authentication, as provided by your web server. In Apache, this is configured simply in your .htaccess or vhost configuration. In IIS, it is a simple GUI option.

Here are the Apache docs., and here are the IIS docs. (this is IIS6, but I think it's still the same in IIS7)

A common Apache configuration looks something like this:

AuthUserFile /path/to/htpasswd-file
AuthName "String to display in login popup"
AuthType Basic
require user username1 username2


来源:https://stackoverflow.com/questions/6542719/how-can-i-password-protect-a-basic-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!