我正在创建我的网站,我需要创建受密码保护的 JavaScript 代码才能访问它。
我是否也需要更改我的 CSS,或者它只会出现在我的 HTML 代码中?
最佳答案
前端 JS 是一种糟糕的保护
// IMPORTANT: This is a JS-for-fun - and a BAD example how to secure your content:
var password = "demo"; // because ANYONE CAN SEE THIS IN VIEW SOURCE!
// Repeatedly prompt for user password until success:
(function promptPass() {
var psw = prompt("Enter your Password");
while (psw !== password) {
alert("Incorrect Password");
return promptPass();
}
}());
alert('WELCOME');
// or show you page content
正确保护您的页面:
与服务器的安全连接和服务器端语言是必经之路。
关于javascript - 如何创建受密码保护的网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20812649/