Is there a way to password protect HTML pages without using a server side language?

后端 未结 10 1618
情深已故
情深已故 2021-01-14 14:36

I have a series of interlinked web pages, and I want to restrict access to these pages by asking the user to provide a login and password. However, my hosting account curren

10条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 14:56

    Yes it is possible but it's not very pretty or even very good.

    • Your index page has an empty div where your restricted content will go.
    • On page load or a link being clicked, a prompt (window.prompt) asks for your password.
    • Your password is hashed and compared to a stored hash ( or array of hashes ) of the correct password in your script.
    • If you have a match you load the content into the div via AJAX
    • You could store the password in a cookie so it isn't prompted for each time ( not very secure but then this isn't a very secure system )
    • You're still not all that secure because the filenames of the pages you'll be loading will be visible in your script but it might keep a very casual surfer out.
    • You could obfusticate the urls thereby requiring some JavaScript knowledge to view. e.g rot13

    You will need a JavaScript hashing script

提交回复
热议问题