...

View Full Version : IF Textbox = value then redirect Help



puraw
12-08-2010, 03:29 AM
OK, my javascript is not that good. So I need your help!

I need to create a text box that will only work if a certain code is entered. So if 1234 is in the text box and submit is clicked, then it will take you to the site. IF not then it will print "Please enter correct code" next to the submit button.

Here is what I have so far:


<input name="txtBox" type="text"/>

<input name="btnButton" type="button" value="Submit" onclick="return checkValue()" />




<script type="text/JavaScript">
function checkValue()
{
var secretcode = document.getElementById("txtBox");


if (secretcode == "1234")
{
document.location.href = 'secret.html';
}
}
</script>

Thank you for your help!

Philip M
12-08-2010, 08:28 AM
<input type="text" id ="txtBox" />
<input type="button" name="btnButton" value="Submit" onclick="checkValue()" />

<script type="text/JavaScript">
function checkValue() {
var secretcode = document.getElementById("txtBox").value;
if (secretcode == "1234"){
window.location.href = 'secret.html';
}
}
</script>But the security level is zero as anyone can see the secret code simply with View Source.


Quizmaster: Which 1996 Leonardo di Caprio film was an adaptation of a famous Shakespeare play?
Contestant: Titanic.

puraw
12-08-2010, 02:04 PM
Thanks for your help. Is there a way to use javascript and be secure? Or am I going to have to rewrite this in php or some other language?

Philip M
12-08-2010, 04:28 PM
Thanks for your help. Is there a way to use javascript and be secure? Or am I going to have to rewrite this in php or some other language?

Javascript is very insecure. Depending on the sophistication of your users and the importance of the material in the site, it is possible to obfuscate/encode the password in such a way that only Javascript experts could decipher it. But anyone who knew how to would crack it in under a minute.

But not only can someone use View Source to see the password, they can read the "secret" URL as well and just navigate directly to it. So that must be obfuscated/encoded as well.

It would be best to use server-side scripting.

puraw
12-08-2010, 08:20 PM
Thank you very much. I will look into coding it with php now. This will work as a temporary fix since it is just going to be for a promo page. Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum