0

I have this JavaScript code

function checkTextField() {
var textVal = document.getElementById("textfield").value;
if (textVal == '', textfield.value.length <= 31)
{
    alert('Wrong Key-Code. Key-Code must have 32 characters!'); 
}
else //Its all about how to decrypt a database file called ,,Salam Horia Allah,,!(good luck hackers)
{
    {
        var text = document.getElementById("textfield").value;
        if (text ==
              "3e6898f92134d05408dfed30b268d9d6",
              "fa0f82cc02a6cdc35072ee5ce2b0c379",
              "6a1df566fcaabca717aa1b81c3e0bd31",
              "dc0beea186c5f5c2110bedbeccc5a7aa",

              "1a317dbc4587268809b67179c391a5da9debb6261e3a3bcf7e6cd2b34356fc40",
              "08a8c9750b3d184e6450b98fa90208bbd6c07171c0cce929bc52be1fdb44b09c",
              "ac8ce3072f41269be4626539650bb1981c2939db0ffd576f240d06b0b7470c11",
              "23a306626c5e9f83d8ce6012f9209fb8f3adcc1a098ffbfafd3c7965ed2c30a6",

              "teBy%udu#uMuGyZe4uTyHeNa5yLy6avyTumypy8uHaGujytaWy",
              "SezyDuXaquneguzuLatydy7e2ygu4y5e7uqe3e6uheVuVeSumu"

              )
        {
            location.href = "http://79.115.70.31:8521/InWork/"
        }
        else {
            alert("Wrong Key")
        }
    }
} 
}

and here is what happen: i have a textbox and a button,when i insert a key from if (text == "3e6898f92134d05408dfed30b268d9d6", "fa0f82cc02a6cdc35072ee5ce2b0c379", "6a1df566fcaabca717aa1b81c3e0bd31", "dc0beea186c5f5c2110bedbeccc5a7aa",

And when someone press that button, I want that script to check if one of that keys are in text field, if is true the request will send to another page, if is not true, show an alert.

But my problem is, whatever I write in that textbox it send me to that page, also I got an alert if textbox have <31 characters.

2 Answers 2

2

The comma operator works inside of an if clause, but it takes the last value, not a logical OR, which is here required.

(An input returns always a string and if empty, the string length is zero. A check for emptiness and a check for a length which is smaller than a value is superfluous, because the length check includes a zero length as well.)

if (textVal == '' || textfield.value.length <= 31)
//                ^^

Beside that, I suggest to use an array for the valid keys for checking and check only if the value is in the array, then proceed or give an alert.

Another point is to assign the value of the input only once and use it in the whole function with the variable. Do not use a mixed style with a variable and document.getElementById("textfield").value together.

function checkTextField() {
    var keys = ["3e6898f92134d05408dfed30b268d9d6", "fa0f82cc02a6cdc35072ee5ce2b0c379", "6a1df566fcaabca717aa1b81c3e0bd31", "dc0beea186c5f5c2110bedbeccc5a7aa", "1a317dbc4587268809b67179c391a5da9debb6261e3a3bcf7e6cd2b34356fc40", "08a8c9750b3d184e6450b98fa90208bbd6c07171c0cce929bc52be1fdb44b09c", "ac8ce3072f41269be4626539650bb1981c2939db0ffd576f240d06b0b7470c11", "23a306626c5e9f83d8ce6012f9209fb8f3adcc1a098ffbfafd3c7965ed2c30a6", "teBy%udu#uMuGyZe4uTyHeNa5yLy6avyTumypy8uHaGujytaWy", "SezyDuXaquneguzuLatydy7e2ygu4y5e7uqe3e6uheVuVeSumu"],
        text = document.getElementById("textfield").value;

    if (keys.indexOf(text) !== -1) {
        location.href = "http://79.115.70.31:8521/InWork/";
    } else {
        alert("Wrong Key");
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Well you need to compare you tex with each key available so

function checkTextField() {
    var textVal = document.getElementById("textfield").value;
    var yourKeys  =[ "3e6898f92134d05408dfed30b268d9d6",
          "fa0f82cc02a6cdc35072ee5ce2b0c379",
          "6a1df566fcaabca717aa1b81c3e0bd31",
          "dc0beea186c5f5c2110bedbeccc5a7aa",

          "1a317dbc4587268809b67179c391a5da9debb6261e3a3bcf7e6cd2b34356fc40",
          "08a8c9750b3d184e6450b98fa90208bbd6c07171c0cce929bc52be1fdb44b09c",
          "ac8ce3072f41269be4626539650bb1981c2939db0ffd576f240d06b0b7470c11",
          "23a306626c5e9f83d8ce6012f9209fb8f3adcc1a098ffbfafd3c7965ed2c30a6",

          "teBy%udu#uMuGyZe4uTyHeNa5yLy6avyTumypy8uHaGujytaWy",
          "SezyDuXaquneguzuLatydy7e2ygu4y5e7uqe3e6uheVuVeSumu"];

  if (textVal == '', textfield.value.length <= 31)
      alert('Wrong Key-Code. Key-Code must have 32 characters!'); 

  else {
    var text = document.getElementById("textfield").value;
    var i = yourKeys.length;
    while(i--){
        if(text == yourKeys[i] )
        location.href = "http://79.115.70.31:8521/InWork/"
    else
        alert("Wrong Key")
     } 
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.