0

I was playing an online game where you have to find the password by viewing the page source (or inspect element). I am confused my this line if(el.value == ""+CodeCode+""). el.value is my guess, and it says I can continue if my guess is: ""+CodeCode+"". "+CodeCode+" is defined as: "+CodeCode+" == "0xf.at_hackit"; but i tried "0xf.at_hackit" (with and without quotes but it is not working). I have been stuck on this for 2 hours so please help!

Here is the code of the game which has a javascript function:

 <!-- :::::::::::::::::==== 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 ====:::::::::::::::::: -->
asked Oct 29, 2017 at 22:45
6
  • 3
    No, == is not defining. CodeCode is defined as "moo6be". That equality check doesn’t do anything. Commented Oct 29, 2017 at 22:48
  • 1
    yes enter the password as: moo6be Commented Oct 29, 2017 at 22:49
  • 1
    @Xufox "moo6be" worked! Can you explain how? Commented Oct 29, 2017 at 22:49
  • @RohanShake Didn’t I already explain it in my comment? Commented Oct 29, 2017 at 22:50
  • 1
    var CodeCode = "moo6be"; Commented Oct 29, 2017 at 22:50

3 Answers 3

1

The code is assigned right after the <script> tag.

The line "+CodeCode+" == "0xf.at_hackit"; does nothing, its just expression that evaluates to false (comparing two different strings), but no assignment, so no side effects.

<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>
answered Oct 29, 2017 at 22:51
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, because of you and JohnD's answers, I understand that ""+CodeCode+"" is "" + CodeCode + "". I will accept asap
It's the same as using just the variable CodeCode (it would also cast it to string, but it was already a string, so its equal).
I know but when I first looked at it I was confused by: "+CodeCode+" == "0xf.at_hackit" and i frankly didn't see: var CodeCode = "moo6be";
1

""+CodeCode+"" is the same thing as: "" + CodeCode + ""

CodeCode is assigned right after the tag:

<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>
answered Oct 29, 2017 at 22:54

Comments

0

The answer is moo6be.

This is because "+CodeCode+" == "0xf.at_hackit"; has double equals, which just means it is a comparison statement (which will just evaluate to false). It is important to note that this is unrelated to the rest of the program.

The main line here is: if(el.value == ""+CodeCode+"").

Which is: "" (empty string) + CodeCode (moo6be) + "" (empty string).

Coder
1,2641 gold badge15 silver badges34 bronze badges
answered Oct 29, 2017 at 22:50

3 Comments

Have no any idea... I answered first and exactly the same as other answers after me. It happens, I think.
Your formatting is kinda confusing - but i think a high rep user was probably trying to answer the question themselves... Everything on SO gets down-voted these days
Rep is overrated ;) Glad that you get the answer anyway.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.