473,383 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Setting up quick and dirty (temporary) password protection using JavaScript

Death Slaught
1,137 1GB
I need to know how to make a username and password login screen for an online game that im making and i need it so i can access that person account and look at their password or edit their account so basicly i need to know how to make a script that will create an account for some one and make it so i can do stuff with it.

Thanks, Death Slaught
Aug 7 '07 #1
25 2331
pbmods
5,821 Expert 4TB
Heya, Death. Welcome to TSDN!

Phew, that's a project! And unfortunately, you're asking about this in the wrong forum.

JavaScript can't do login stuff like that. You have to take care of that stuff on the server-side using a language such as PHP.

PS Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as, 'need help' actually get FEWER responses?).
Aug 7 '07 #2
Death Slaught
1,137 1GB
i need help creating a script that allows the person with the correct password to enter nothin fancy i just need it so my friends can access a page and my other friends cant......i know a little about javascript so thats why i chose this language.

Thanks, Death Slaught
Aug 8 '07 #3
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem (did you know that threads whose titles contain three words or less actually get FEWER responses?).
Aug 8 '07 #4
pbmods
5,821 Expert 4TB
Heya, Death.

Even easier than trying to do it in JavaScript, simply add this statement to the top of your page:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     if($_GET['password'] != 'thepasswordgoeshere')
  3.     {
  4.         exit('You didn\'t say the magic word.');
  5.     }
  6. ?>
  7.  
Aug 8 '07 #5
Death Slaught
1,137 1GB
Heya, Death.

Even easier than trying to do it in JavaScript, simply add this statement to the top of your page:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     if($_GET['password'] != 'thepasswordgoeshere')
  3.     {
  4.         exit('You didn\'t say the magic word.');
  5.     }
  6. ?>
  7.  
thanks but im sorta new to javascript and its the only scripting language i know im trying to learn more about it and others but with school starting back its not gona be easy what tags should i use and is this even javascript doesnt really look like it but if its not could you please explain what it is and where i save it and do i still save it under .html

Thanks again
Aug 8 '07 #6
Here is a javascript function that will check your password if your website doesn't support php.
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.  function check_entry()
  3.  {
  4.   if(document.login.password.value == "yourpassword")
  5.   {
  6.    return true;
  7.   }
  8.   return false;
  9.  }
  10. </script>
  11.  
  12. <form name="login" action="location" onsubmit="return check_entry();">
  13.  <input type="password" name="password">
  14.  <input type="submit" value="Login">
  15. </form>
  16.  
Please be aware that if someone were to look at the source code, they could see the password and where a correct password would take you.
Aug 8 '07 #7
pbmods
5,821 Expert 4TB
Heya, Death.

You posted a similar question in the PHP forum, so I assumed that a PHP solution would be OK.

The issue with a JavaScript solution, as johnhjohn pointed out, is that ultimately, you are presenting the password to the User in plaintext if he knows where to look.
Aug 8 '07 #8
Death Slaught
1,137 1GB
Heya, Death.

You posted a similar question in the PHP forum, so I assumed that a PHP solution would be OK.

The issue with a JavaScript solution, as johnhjohn pointed out, is that ultimately, you are presenting the password to the User in plaintext if he knows where to look.
yes and no i want this to be a simple one just a password but i want the other one a username and password that i can look at and edit its for a game im going to make so its for my players accounts and would you have a script for blocking viewers from seeing the script and also im trying to put an image on it this is what im tryin

1 <html>
2 <embed src="C:\Documents and Settings\Owner\My Documents\My Pictures\imagename">
3</html>

that just gives me a box i tried putting in width and height but it was fruitless i know im doing something wrong so if you could help out on this to it would be great.

Thanks man
Aug 8 '07 #9
Death Slaught
1,137 1GB
both of these question are directed to either of you i just clicked on that reply
Aug 8 '07 #10
Death Slaught
1,137 1GB
Here is a javascript function that will check your password if your website doesn't support php.
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.  function check_entry()
  3.  {
  4.   if(document.login.password.value == "yourpassword")
  5.   {
  6.    return true;
  7.   }
  8.   return false;
  9.  }
  10. </script>
  11.  
  12. <form name="login" action="location" onsubmit="return check_entry();">
  13.  <input type="password" name="password">
  14.  <input type="submit" value="Login">
  15. </form>
  16.  
Please be aware that if someone were to look at the source code, they could see the password and where a correct password would take you.
the script works great most of the poeple that know about my site dont know how to view source so its great but as i said before if you guys know how to block people from seeing that would be great just in case
Aug 8 '07 #11
There isn't a way to block the script from view, since it isn't a server-side script. And for the image, use the <img> tag:

Expand|Select|Wrap|Line Numbers
  1. <img src="C:\Documents and Settings\Owner\My Documents\My Pictures\imagename"></img>
  2.  
Hope this helps.
Aug 8 '07 #12
Death Slaught
1,137 1GB
There isn't a way to block the script from view, since it isn't a server-side script. And for the image, use the <img> tag:

Expand|Select|Wrap|Line Numbers
  1. <img src="C:\Documents and Settings\Owner\My Documents\My Pictures\imagename"></img>
  2.  
Hope this helps.


thanks i knew it had source in it for sure i thought it had img in it as well but i thought it had to had embed lol thanks and also is there any way to encrypt the code so they can see it but not read it and the comp still be able to read it?
Aug 8 '07 #13
Death Slaught
1,137 1GB
well john its an improvement but its a white box with a red x in it any ideas why?
Aug 8 '07 #14
Death Slaught
1,137 1GB
well john its an improvement but its a white box with a red x in it any ideas why?
ignore this coment i forgot to put .jpg after the image name it works thanks again
Aug 8 '07 #15
Double check the path of the image (where it is located) and make sure it is typed correctly.
Aug 8 '07 #16
Death Slaught
1,137 1GB
lol it works great i jus have one more question how would i combine the 2 scripts the password script and the image script so that they would have to login to see the image would that involve redirecting them to another page if they got it right?
Aug 8 '07 #17
If you want to keep the script simple, redirecting to another page would be good. If someone looks at the source, however, they might be able to access the image without entering a password.
Aug 8 '07 #18
Death Slaught
1,137 1GB
If you want to keep the script simple, redirecting to another page would be good. If someone looks at the source, however, they might be able to access the image without entering a password.
this just keeps getting better lol well i have an idea but i really dont think it will work what if i used this script

1 <html>
2 <script>
3 var user1;
4 user1=prompt("password");
5 </script>
6 </html>

after useing the prompt thing would it be possible to use the if-then format so if they typed in the correct word it would show watever was there and if they got it wrong it would alert them so until they got it right or exited the site?
Aug 8 '07 #19
Death Slaught
1,137 1GB
instead of until they got it right leting them try it a number of times and if they got it wrong every time they get redirected to another if its possible
Aug 8 '07 #20
This script will ask them if they want to try the password again. If they say no, they will be redirected to somewhere else.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  <script language="javascript" type="text/javascript">
  3.  var user1;
  4.  function login()
  5.  {
  6.  user1=prompt("password");
  7.   if(user1 == "thepassword")
  8.   {
  9.    top.window.location="location you want";
  10.   } else {
  11.    if(confirm("The password you entered was incorrect.\n\nWould you like to try again?"))
  12.    {
  13.     login();
  14.    } else {
  15.   top.window.location="password wrong location";
  16.    }
  17.   }
  18.  }
  19.  
  20.  login();
  21.  </script>
  22.  
  23.  
Aug 8 '07 #21
Death Slaught
1,137 1GB
This script will ask them if they want to try the password again. If they say no, they will be redirected to somewhere else.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  <script language="javascript" type="text/javascript">
  3.  var user1;
  4.  function login()
  5.  {
  6.  user1=prompt("password");
  7.   if(user1 == "thepassword")
  8.   {
  9.    top.window.location="location you want";
  10.   } else {
  11.    if(confirm("The password you entered was incorrect.\n\nWould you like to try again?"))
  12.    {
  13.     login();
  14.    } else {
  15.   top.window.location="password wrong location";
  16.    }
  17.   }
  18.  }
  19.  
  20.  login();
  21.  </script>
  22.  
  23.  
thanks alot you've been so helpfull where did you learn so much about javascript? ive read about 6 books bigger than my head and don't know sqaut.
Aug 8 '07 #22
I took some tutorials on javascript from an assortment of sites. It took awhile to learn things, but after making many scripts, I got the hang of it.

One good site to learn from is www.w3schools.com.

I'm glad I could help :)
Aug 8 '07 #23
Death Slaught
1,137 1GB
ill have to go there somtime that script is perfect though just what i needed i just have 1 more question and ill be done scroll down and look for another post of myn on Controlling/ Playing a music file and tell me if you can help there this one is getting crouded lol thanks again
Aug 8 '07 #24
Yeah, no problem. I'll take a look.
Aug 8 '07 #25
acoder
16,027 Expert Mod 8TB
Merged threads.
Aug 9 '07 #26

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: juglesh | last post by:
<body><div align="center"> <?php if (!isset($password)){ ?><form action="<?php $_SERVER; ?>" method="post"> type password here&nbsp;<input name="password" type="text" size="8"> then <input...
10
by: Mike Painter | last post by:
I need a scheme to give people password access to JavaScript quizzes that I have. I've done a lot of programming but almost no JS. Probably one password per person for each of five tests. I...
10
by: Max | last post by:
Hello all, I am trying to protect a page within my site with a JS password scheme. Now I know JS can be quite easily "circumvented", but I came by a code below. My question is: 1. Is there...
7
by: Eagle35 | last post by:
any one now any good java/Html for password pages so i can protect some pages?? Thanks
2
by: chris | last post by:
Hi, I will be looking to use gatekeeper or some other javascript method of password protection but... Once there I need a way of resticting access to a page to stop someone from bookmarking...
6
by: Roger Judd | last post by:
Hello, I need the JavaScript code for a low security password that I can put into my homepage so only club members can access certain pages of info. Can anyone give me an example please My...
7
by: Borked Pseudo Mailed | last post by:
Seeking feedback on Password Protection via Java/JavaScript ONLY (no cgi): SEE: http://online_tools.home.att.net/tools.html *AND* http://online_tools.home.att.net/extraCode.htm Thanks.
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: Noel S Pamfree | last post by:
Problem 1 ======= I need to create a page for a friend who operates a school website. She needs to set up a page so that only the Governors can access it. I thought I'd try to use JavaScript to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.