简体   繁体   English

JavaScript - 循环的意外标识符

[英]JavaScript - Unexpected identifier for loop

I am trying to write a kind of brute force script in javascript!我正在尝试用 javascript 编写一种蛮力脚本! This is what I have so far:这是我到目前为止:

var charset = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j,", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];

function bruteForce() {

    var password = document.getElementById("enteredPassword").value;
    var crackedPassword = "";

    while (true) {
        if (crackedPassword != password) {
            for (int i; i < charset.lenght; i++) {
                crackedPassword += charset[i];
                document.getElementById("currentPassword").value = crackedPassword;
            }
        } else {

            document.getElementById("currentPassword").value = crackedPassword;
            alert("finished");
        }
    }
}

It gives me the following error: Uncaught SyntaxError: Unexpected identifier它给了我以下错误: Uncaught SyntaxError: Unexpected identifier
the line causing the problem: for(int i = 0; i < charset.lenght; i++){导致问题的行: for(int i = 0; i < charset.lenght; i++){


And: Uncaught ReferenceError: bruteForce is not defined并且: Uncaught ReferenceError: bruteForce is not defined
line: <input onClick = "bruteForce()" name="input" type="image" src="arrow.jpg" align="right" />行: <input onClick = "bruteForce()" name="input" type="image" src="arrow.jpg" align="right" />

I thing it has to do with that crackedPassword += charset[i];我认为这与crackedPassword += charset[i];
But what I saw here , confused me, because there has to be another cause!但是我在这里看到的让我很困惑,因为一定有另一个原因!

for(int i = 0; i < charset.lenght; i++){

should be for(var i = 0; i < charset.length; i++){应该是for(var i = 0; i < charset.length; i++){

Also inline event handlers like <input onClick = "bruteForce()" name="input" type="image" src="arrow.jpg" align="right" /> expect the handler to be in global scope.还有像<input onClick = "bruteForce()" name="input" type="image" src="arrow.jpg" align="right" />这样的内联事件处理程序期望处理程序在全局范围内。

So if the code you shared is enclosed in some other wrapper function, it probably won't work.因此,如果您共享的代码包含在其他一些包装函数中,则它可能无法工作。 Otherwise it's the first syntax error causing the second as well...否则,第一个语法错误也会导致第二个......

Length is spelt wrong in your for loop.您的 for 循环中的长度拼写错误。 It should be length not lenght.它应该是长度而不是长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM