Results 1 to 4 of 4

Thread: Please help with code for simple password field

  1. #1
    Join Date
    Jan 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help with code for simple password field

    Hi all,

    I'm obviously not an expert. Can anyone please help me with html code to make a simple password field? I need it to redirect to one page if the password is correct and also redirect to a different page if the password is incorrect.

    It doesn't have to be a very secure login. It's for a simple website form to submit an answer that is either right or wrong.

    The following code is what I've been playing with and the redirect for the false password doesn't work. Also, it's a button with a popup prompt and I would actually prefer a text field to submit on keying enter.

    If anyone can help me with either problem, I would so appreciate any help.

    Code:
    <html>
    <HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    function LogIn(){
    password="mypassword";
    password=prompt("Enter password:","");
    password=password.toLowerCase();
    if (password=="mypassword") { 
    loggedin=true;
    window.location="http://MyURLredirectRightPWD.html";
    }
    if (password==false) {
    loggedin=false;
    window.location="http://MyURLredirectWrongPWD.html";
    }
    }
    </SCRIPT> 
    <BODY>
    <center>
    <form><input type=button value="Enter Password" onClick="LogIn()"></form>
    </center>
    </body>
    </html>
    Last edited by jscheuer1; 01-08-2017 at 11:53 PM. Reason: format code

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,094
    Thanks
    1
    Thanked 205 Times in 201 Posts

    Default

    Hi there Nicole107,

    and a warm welcome to these forums.

    Bearing in mind that this a fun rather than a real secure login, try this...

    Code:
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">
    
    <title>untitled document</title>
    
    <!--<link rel="stylesheet" href="screen.css" media="screen">-->
    
    <style media="screen">
    body {
        background-color: #f0f0f0;
        text-align: center;
     }
    #login {
        display: inline-block;
        padding: 1em;
        border: 0.06em solid #999;
        border-radius: 0.5em;
        background-color: #fff;
        box-shadow: inset 0 0 1em #999, 0.3em 0.3em 0.3em #999;   
     }
    </style>
    
    </head>
    <body>
    
    <form id="login" action="http://www.coothead.co.uk/images/"><!--this is for an incorrect password, or for those with JavaScript disabled -->
     <label for="pswd">Enter Password: </label>
     <input id="pswd" type="password" name="password">
     <input id="sbmt" type="submit" value="log in">
    </form>
    
    <script>
    (function() {
       'use strict';
       document.getElementById('sbmt').addEventListener('click',
    function(){
       if(document.getElementById('pswd').value.toLowerCase()==='mypassword'){
          document.getElementById('login').action='http://www.dynamicdrive.com/forums/'; /* this is for a correct password */
        }},false);
    }());
    </script>
    
    </body>
    </html>

    coothead
    ~ the original bald headed old fart ~

  3. #3
    Join Date
    Jan 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much!

  4. #4
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,094
    Thanks
    1
    Thanked 205 Times in 201 Posts

    Default


    No problem, you're very welcome.

    coothead
    ~ the original bald headed old fart ~

Similar Threads

  1. Need simple way to password protect a web page..
    By yuppicide in forum Looking for such a script or service
    Replies: 2
    Last Post: 09-28-2016, 02:02 PM
  2. Simple PHP password form
    By bluewalrus in forum PHP
    Replies: 9
    Last Post: 10-14-2008, 02:28 AM
  3. change the type of a field from text to password
    By sanoop in forum JavaScript
    Replies: 9
    Last Post: 02-01-2007, 01:58 PM
  4. simple password problem
    By sunny in forum JavaScript
    Replies: 6
    Last Post: 07-05-2005, 08:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •