JavaScript函数无法识别正确的密码

时间:2017-10-29 22:45:50

标签: javascript html src

我正在玩一个在线game,您必须通过查看页面源(或检查元素)来查找密码。我很困惑我的这句话if(el.value == ""+CodeCode+"")el.value是我的猜测,如果我的猜测是:""+CodeCode+"",我就可以继续。 “+ CodeCode +”定义为:"+CodeCode+" == "0xf.at_hackit";但我尝试了“0xf.at_hackit”(有和没有引号但它不起作用)。我已经坚持了2个小时,所以请帮忙!

以下是具有javascript功能的游戏代码:

     <!-- :::::::::::::::::==== GAME STARTS HERE ====::::::::::::::::: -->
        <h1>Level 10</h1>
        <p>Try not to be fooled</p>
        <input id="pw" type="password" />
        <br/><input type="button" value="OK" onClick="checkPW()"/>
        <script type="text/javascript">var CodeCode = "moo6be";

            function checkPW()
            {
                "+CodeCode+" == "0xf.at_hackit";
                var el = document.getElementById("pw");
                if(el.value == ""+CodeCode+"")
                    document.location.href="?pw="+el.value;
                else alert("Wrong password");
            }

        </script>
    <!-- ::::::::::::::::::==== GAME ENDS HERE ====:::::::::::::::::: -->

3 个答案:

答案 0 :(得分:1)

代码是在<script>代码后面分配的。

"+CodeCode+" == "0xf.at_hackit";什么都不做,它只是表达式,计算结果为false(比较两个不同的字符串),但没有赋值,所以没有副作用。

<script type="text/javascript">var CodeCode = "moo6be"; // <==== HERE 

    function checkPW() {
        "+CodeCode+" == "0xf.at_hackit";       // <==== this does nothing, its just expression that evaluates to false, but no assignment
        var el = document.getElementById("pw");
        if(el.value == ""+CodeCode+"")         // <==== this is the same as `if(el.value == CodeCode)`
            document.location.href="?pw="+el.value;
        else alert("Wrong password");
    }
</script>

答案 1 :(得分:1)

""+CodeCode+"""" + CodeCode + ""

相同

CodeCode紧接在标记之后分配:

<script type="text/javascript">var CodeCode = "moo6be"; // HERE

function checkPW()
        {
            "+CodeCode+" == "0xf.at_hackit"; // this does nothing, its just expression that evaluates to false - this is meant to trick you
            var el = document.getElementById("pw");
            if(el.value == ""+CodeCode+"")
                document.location.href="?pw="+el.value;
            else alert("Wrong password");
        }

    </script>

答案 2 :(得分:0)

答案是moo6be

这是因为"+CodeCode+" == "0xf.at_hackit";有两个等号,这意味着它是一个比较语句(它只会评估为false)。值得注意的是,这与该计划的其他部分无关。

这里的主线是:if(el.value == ""+CodeCode+"")

这是:"" (empty string) + CodeCode (moo6be) + "" (empty string)

相关问题