I need help to make a javascript code

to make 1 of my homepage password protected

Page 1 of 1

11 Replies - 1547 Views - Last Post: 07 March 2008 - 11:30 AM

#1 Betsy-H  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-March 08

I need help to make a javascript code

Post icon  Posted 07 March 2008 - 08:32 AM

I need help to make a javascript code,to make 1 of my homepage password protected.

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

Is This A Good Question/Topic? 0
  • +

Replies To: I need help to make a javascript code

#2 pertheusual  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 245
  • Joined: 26-January 08

Re: I need help to make a javascript code

Posted 07 March 2008 - 08:50 AM

You might want to note the first "IMPORTANT" section in the link.

You really shouldn't use Javascript for security. You should use PHP or CGI.

Do you have the possibility on your server?
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: I need help to make a javascript code

Posted 07 March 2008 - 08:55 AM

For starters you need to put your code inside code tags like :code: . It does make the code easier to read through. Second using document.password1 wont work in all browsers. Some support this and some dont. To make it work in all browsers you need a script that will check what DOM options are available for the browser currently viewing the page. I use this script I wrote in all my Javascript


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.
Was This Post Helpful? 0
  • +
  • -

#4 Betsy-H  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-March 08

Re: I need help to make a javascript code

Posted 07 March 2008 - 09:19 AM

Thanks. This was new to me, Have too read closer.
Great thanks for reply so fast to my problems.
hug from Betsy
Was This Post Helpful? 0
  • +
  • -

#5 Betsy-H  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-March 08

Re: I need help to make a javascript code

Posted 07 March 2008 - 09:40 AM

Sorry to bee a litle "green"about this, so the script

_________________

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

Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: I need help to make a javascript code

Posted 07 March 2008 - 09:41 AM

Your secured site is different from your login site? Or were you referring to pages. That script needs to go in your login page.
Was This Post Helpful? 0
  • +
  • -

#7 Betsy-H  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-March 08

Re: I need help to make a javascript code

Posted 07 March 2008 - 09:47 AM

Can I have only 1 site??
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
Was This Post Helpful? 0
  • +
  • -

#8 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: I need help to make a javascript code

Posted 07 March 2008 - 09:48 AM

You don't need 2 sites for this. In your site you have a login page which allows access to the password protected pages in your site. You're going to have to add code in each page to check if the user has been authenticated though.
Was This Post Helpful? 0
  • +
  • -

#9 Betsy-H  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-March 08

Re: I need help to make a javascript code

Posted 07 March 2008 - 09:53 AM

Thanks , I will try it, and than come back, so I don't have to nag you too much.
Great thanks.
Betsy

This post has been edited by Betsy-H: 07 March 2008 - 09:53 AM

Was This Post Helpful? 0
  • +
  • -

#10 Betsy-H  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-March 08

Re: I need help to make a javascript code

Posted 07 March 2008 - 10:58 AM

I have tried, but I may do it the wrong way, because I have only worked with HTML codes before. so I have only plased the code direct in to the site.
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
Was This Post Helpful? 0
  • +
  • -

#11 Betsy-H  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-March 08

Re: I need help to make a javascript code

Posted 07 March 2008 - 11:04 AM

View Postpertheusual, on 7 Mar, 2008 - 08:50 AM, said:

You might want to note the first "IMPORTANT" section in the link.

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
Was This Post Helpful? 0
  • +
  • -

#12 Betsy-H  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-March 08

Re: I need help to make a javascript code

Posted 07 March 2008 - 11:30 AM

I have now download the Adobe reader with javascript for new beginners, I will read , and maybe learn a litle bit more.
Thanks again.
Betsy
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1