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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Death Slaught
    Top Contributor
    • Aug 2007
    • 1137

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

    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
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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?).

    Comment

    • Death Slaught
      Top Contributor
      • Aug 2007
      • 1137

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

      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

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Changed thread title to better describe the problem (did you know that threads whose titles contain three words or less actually get FEWER responses?).

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Death.

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

          [code=php]
          <?php
          if($_GET['password'] != 'thepasswordgoe shere')
          {
          exit('You didn\'t say the magic word.');
          }
          ?>
          [/code]

          Comment

          • Death Slaught
            Top Contributor
            • Aug 2007
            • 1137

            #6
            Originally posted by pbmods
            Heya, Death.

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

            [code=php]
            <?php
            if($_GET['password'] != 'thepasswordgoe shere')
            {
            exit('You didn\'t say the magic word.');
            }
            ?>
            [/code]
            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

            Comment

            • johnhjohn
              New Member
              • Dec 2006
              • 43

              #7
              Here is a javascript function that will check your password if your website doesn't support php.
              Code:
              <script language="javascript" type="text/javascript">
               function check_entry()
               {
                if(document.login.password.value == "yourpassword")
                {
                 return true;
                }
                return false;
               }
              </script>
              
              <form name="login" action="location" onsubmit="return check_entry();">
               <input type="password" name="password">
               <input type="submit" value="Login">
              </form>
              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.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                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.

                Comment

                • Death Slaught
                  Top Contributor
                  • Aug 2007
                  • 1137

                  #9
                  Originally posted by pbmods
                  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:\Documen ts and Settings\Owner\ My Documents\My Pictures\imagen ame">
                  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

                  Comment

                  • Death Slaught
                    Top Contributor
                    • Aug 2007
                    • 1137

                    #10
                    both of these question are directed to either of you i just clicked on that reply

                    Comment

                    • Death Slaught
                      Top Contributor
                      • Aug 2007
                      • 1137

                      #11
                      Originally posted by johnhjohn
                      Here is a javascript function that will check your password if your website doesn't support php.
                      Code:
                      <script language="javascript" type="text/javascript">
                       function check_entry()
                       {
                        if(document.login.password.value == "yourpassword")
                        {
                         return true;
                        }
                        return false;
                       }
                      </script>
                      
                      <form name="login" action="location" onsubmit="return check_entry();">
                       <input type="password" name="password">
                       <input type="submit" value="Login">
                      </form>
                      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

                      Comment

                      • johnhjohn
                        New Member
                        • Dec 2006
                        • 43

                        #12
                        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:

                        Code:
                        <img src="C:\Documents and Settings\Owner\My Documents\My Pictures\imagename"></img>
                        Hope this helps.

                        Comment

                        • Death Slaught
                          Top Contributor
                          • Aug 2007
                          • 1137

                          #13
                          Originally posted by johnhjohn
                          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:

                          Code:
                          <img src="C:\Documents and Settings\Owner\My Documents\My Pictures\imagename"></img>
                          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?

                          Comment

                          • Death Slaught
                            Top Contributor
                            • Aug 2007
                            • 1137

                            #14
                            well john its an improvement but its a white box with a red x in it any ideas why?

                            Comment

                            • Death Slaught
                              Top Contributor
                              • Aug 2007
                              • 1137

                              #15
                              Originally posted by Death Slaught
                              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

                              Comment

                              Working...