-2

I am trying to write a kind of brute force script in 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
the line causing the problem: for(int i = 0; i < charset.lenght; i++){


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

I thing it has to do with that crackedPassword += charset[i];
But what I saw here, confused me, because there has to be another cause!

Community
  • 1
  • 1
Niemand
  • 21
  • 4
  • 8

2 Answers2

2

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

should be 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.

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...

T J
  • 42,762
  • 13
  • 83
  • 138
0

Length is spelt wrong in your for loop. It should be length not lenght.

kjpc-tech
  • 531
  • 1
  • 5
  • 8