PDA

View Full Version : A box where if you type in the right word you will be redirected to another page



Inspired
11-06-2005, 04:05 PM
I'm working on website that will have riddles on it. It is kind of a game. If people find out the answer, they should be able to write it down in a box and press enter. If the answer was correct, they should be redirected to a new page with the next riddle. If the answer was wrong, either nothing should happen or it should say "Your answer was wrong, please try again" or something simular.

Any idea on how I achieve this?

Twey
11-06-2005, 04:43 PM
A slight modification to the "encrypted password" script should serve us.

<script type="text/javascript">
//Encrypted Password script- By Rob Heslop
// Modified by Twey to remove username field and check onchange.
//Script featured on Dynamic Drive
//Visit http://www.dynamicdrive.com

function submitentry(field){
var password = field.value.toLowerCase()
var passcode = 1
for(var i = 0; i < password.length; i++) {
passcode *= password.charCodeAt(i);
}
//CHANGE THE NUMBER BELOW TO REFLECT YOUR PASSWORD
if(passcode==126906300)
//CHANGE THE NUMBER ABOVE TO REFLECT YOUR PASSWORD
window.location=password+".htm"
</script>
<input type="password" onchange="submitentry(this);">
Get your passcode from http://www.dynamicdrive.com/dynamicindex9/password.htm .

Inspired
11-08-2005, 12:55 PM
I tried it out with a test page:

http://www.inspired.be/riddles/start.htm

It doesn't seem to work. Can someone take a look and see why it's not working?

When people got the word wrong it should say "It looks like you got the wrong answer!". But it doesn't do anything. If you answer right, it doesn't do anything right either.

For those who want to test it, the answer should be ebay.

Twey
11-08-2005, 02:43 PM
Change:

<input type="button" value="Submit" onClick="submitentry()">
to:

<input type="button" value="Submit" onClick="submitentry(this.form.level)">

Inspired
11-08-2005, 05:42 PM
I have changed the line and still doesn't do a thing.

The changed page can still be found here:
http://www.inspired.be/riddles/start.htm

Twey
11-08-2005, 07:27 PM
Ahaha, that was stupid. I was assuming you'd put the elements in a form. Either put them in a form, or use:

document.getElementsByName("level")[0]instead of this.form.level.

Inspired
11-08-2005, 08:41 PM
I changed it, but it's still not responding.

Twey
11-09-2005, 11:35 AM
Firstly, I did something stupid again. Secondly, you didn't do what I said.
Your onclick event looks like this:

onClick="submitentry(document.getElementsByName("level)[0])
which compares badly to my:

onclick="submitentry(document.getElementsByName("level")[0])"
which ought to be:

onclick="submitentry(document.getElementsByName('level')[0])"
(single quotes instead of double quotes).

Inspired
11-09-2005, 06:07 PM
Firstly, I did something stupid again. Secondly, you didn't do what I said.
Your onclick event looks like this:

onClick="submitentry(document.getElementsByName("level)[0])

You must have looked wrong, because it is


<input type="button" value="Submit" onClick="submitentry(document.getElementsByName("level")[0])">

Just like your code. I basicly copied and paste it, so I don't know why it shows any different at your computer.



which ought to be:

onclick="submitentry(document.getElementsByName('level')[0])"
(single quotes instead of double quotes).

Thank you :) It finally works. I really appreciate all the help you gave me.

I only have one practical question, how hard is it to crack this code? Are they online coverters that would make it able for users to cheat?

Twey
11-09-2005, 07:46 PM
It's quite tricky to crack, I believe, though far from invulnerable. It can't just be decrypted, as it's a very simple has algorithm. However, bruteforcing probably wouldn't take too long (comparatively - we're talking days here). If anyone's that desperate to crack your little puzzle, however, you really shouldn't be using client-side scripting :)

Inspired
11-10-2005, 06:02 PM
I just want to be sure that people can't just copy the password and paste it in some kind of converter. I just want to make sure that easy cheating isn't possible.

Twey
11-10-2005, 06:25 PM
No, there's no way to cheat easily. It's a hash: once it's been hashed, there's no way to find out what the original word was except by trial and error, and even then you could get a different password to the original one.