I need help to make a javascript codeto make 1 of my homepage password protected
Page 1 of 1
11 Replies - 1316 Views - Last Post: 07 March 2008 - 11:30 AM
#1
I need help to make a javascript code
Posted 07 March 2008 - 08:32 AM
I have tried for 3 days on a code I found in here, but maybe I haven't understood it right.
http://www.dynamicdr...x9/password.htm
Here is what I did.
I name the page the same as the password,
music4fr
I change the number in the code, after I had Encrypted the username and the password
I use this code on the page where the log in is.
<form name="password1">
<strong>Enter username: </strong>
<input type="text" name="username2" size="15">
<br>
<strong>Enter password: </strong>
<input type="password" name="password2" size="15">
<input type="button" value="Submit" onclick="submitentry()">
</form>
And in the protected page I put this code
<script>
//Encrypted Password script- By Rob Heslop
//Script featured on Dynamic Drive
//Visit http://www.dynamicdrive.com
function submitentry(){
password = document.password1.password2.value.toLowerCase()
username = document.password1.username2.value.toLowerCase()
passcode = 1
usercode = 1
for(i = 0; i < password.length; i++) {
passcode *= password.charCodeAt(i);
}
for(x = 0; x < username.length; x++) {
usercode *= username.charCodeAt(x);
}
//CHANGE THE NUMBERS BELOW TO REFLECT YOUR USERNAME/PASSWORD
if(usercode==2.1671902115999703e+22&&passcode==9218134922396400)
//CHANGE THE NUMBERS ABOVE TO REFLECT YOUR USERNAME/PASSWORD
{
window.location=password+"music4fr.htm"}
else{
alert("password/username combination wrong")}
}
</script>
So if somebody can tell me what I did wrong, I will be happy.
hug from Betsy
Replies To: I need help to make a javascript code
#2
Re: I need help to make a javascript code
Posted 07 March 2008 - 08:50 AM
You really shouldn't use Javascript for security. You should use PHP or CGI.
Do you have the possibility on your server?
#3
Re: I need help to make a javascript code
Posted 07 March 2008 - 08:55 AM
function DOMCall(name)
{
//Checks the DOM features available
if (document.layers) //checks document.layers
return document.layers[name];
else if (document.all) //checks document.all
return document.all[name];
else if (document.getElementById) //checks getElementById
return document.getElementById(name);
}
Also, in your redirect at the bottom of your code is incorrect according to his example. You will notice he has window.location=password+".htm" and you have window.location=password+"music4fr.htm" According to the directions of his script you should have window.location=password + ".htm";.
So your script should look like
function submitentry(){
//here we will use the DOMCall function as shown above
password = DOMCall("password2").value.toLowerCase();
username = DOMCall("username2").value.toLowerCase();
passcode = 1;
usercode = 1;
for(i = 0; i < password.length; i++) {
passcode *= password.charCodeAt(i);
}
for(x = 0; x < username.length; x++) {
usercode *= username.charCodeAt(x);
}
//CHANGE THE NUMBERS BELOW TO REFLECT YOUR USERNAME/PASSWORD
if(usercode==2.1671902115999703e+22&&passcode==9218134922396400)
//CHANGE THE NUMBERS ABOVE TO REFLECT YOUR USERNAME/PASSWORD
{
window.location=password + "htm";}
else{
alert("password/username combination wrong");}
}
Also, you were missing the semi-colons at the end of several lines, so I also added those to the script. also, as pertheusual stated, it is never a good idea to use client side security like that. Anyone can view the source of your script and know exactly what to enter to get by your security.
#4
Re: I need help to make a javascript code
Posted 07 March 2008 - 09:19 AM
Great thanks for reply so fast to my problems.
hug from Betsy
#5
Re: I need help to make a javascript code
Posted 07 March 2008 - 09:40 AM
_________________
function submitentry(){
//here we will use the DOMCall function as shown above
password = DOMCall("password2").value.toLowerCase();
username = DOMCall("username2").value.toLowerCase();
passcode = 1;
usercode = 1;
for(i = 0; i < password.length; i++) {
passcode *= password.charCodeAt(i);
}
for(x = 0; x < username.length; x++) {
usercode *= username.charCodeAt(x);
}
//CHANGE THE NUMBERS BELOW TO REFLECT YOUR USERNAME/PASSWORD
if(usercode==2.1671902115999703e+22&&passcode==9218134922396400)
//CHANGE THE NUMBERS ABOVE TO REFLECT YOUR USERNAME/PASSWORD
{
window.location=password + "htm";}
else{
alert("password/username combination wrong");}
}
____________________
Is to be placed on my protected site??
and what about the log in site??
hugs from Betsy
This post has been edited by Betsy-H: 07 March 2008 - 09:41 AM
#6
Re: I need help to make a javascript code
Posted 07 March 2008 - 09:41 AM
#7
Re: I need help to make a javascript code
Posted 07 March 2008 - 09:47 AM
I was sure I had to have 2 site,(1 where the log in is, and 1 protected)
I'm testing to use this site as a the protected site
http://www.freewebs....ko/music4fr.htm
#8
Re: I need help to make a javascript code
Posted 07 March 2008 - 09:48 AM
#9
Re: I need help to make a javascript code
Posted 07 March 2008 - 09:53 AM
Great thanks.
Betsy
This post has been edited by Betsy-H: 07 March 2008 - 09:53 AM
#10
Re: I need help to make a javascript code
Posted 07 March 2008 - 10:58 AM
this page suport some javascript, becuse I have a online page, that doesn't work the same way.
So this code shows when I put it direct in the site/page,
So it maybe safer, but I have not learn how to put code like this in the source code(except I did it to my space for adding alot of extra html boxes.)
But on this homepage , I have a javascript to let some of my pages open in a new window without a IE bar, så people don't can go to source code, and I have right click protect the same site, so they don't know where they are.
Of course If I should use it for something involved money, I had to have it more safe.
I'm so sorry, but I still need more help.
1.
The code to put in the log in page
2.
the code to put in the protected page.
3.
Do I put the codes in source code, and how.
Sorry for being so "green"
Betsy
#11
Re: I need help to make a javascript code
Posted 07 March 2008 - 11:04 AM
pertheusual, on 7 Mar, 2008 - 08:50 AM, said:
You really shouldn't use Javascript for security. You should use PHP or CGI.
Do you have the possibility on your server?
I have never heard of this, is it difficult, just use HTML, and only a few simpel Javascript,
Is it something I have to download.??
Im willing to learn.
Betsy
#12
Re: I need help to make a javascript code
Posted 07 March 2008 - 11:30 AM
Thanks again.
Betsy
|
|

New Topic/Question
Reply



MultiQuote




|