0

I want to password protect my website.

I have found this code from another developer but want it to redirect to index3.html when the password entered is correct.

Can someone please show me if this is possible using this code?

http://jsfiddle.net/LpdQm/16/

$("#b").click(function() {
    var password = "password";
    if($("#pass").val() !== password) {
        $("#err").text("Incorrect password");
    }
    else {
        $("#err").text("Password correct! Do whatever you need to do here.");   
    }
});
4

1 回答 1

0

如果您只想重定向用户,请替换:

$("#err").text("Password correct! Do whatever you need to do here.");

有了这个:

window.location.href = "http://someUrl";

其中“someUrl”是您要将用户定向到的 URL。

但是,正如对问题本身的评论中所指出的那样,像这样基于 JavaScript 的密码保护并不安全。任何用户都可以简单地查看 JavaScript 源代码并查看预期的密码是什么。对于任何类型的安全性,您都需要使用某种服务器端密码检查,用户看不到代码。有很多选项(PHP、Ruby、Python、ASP.NET、Java,不胜枚举),您选择哪一个取决于您自己。

于 2013-09-29T18:13:54.020 回答