Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with certain kinds of forms

    I'm trying to write an html page, and I want there to be a "link" that's actually just a place to enter a password, and if it's correct, to redirect to another page, and if it's false, then it brings up a javascript alert. EXAMPLE-


    Password is Cat

    There would be a place to enter a password, and if Cat is entered, then it redirects to the "locked" page.

    Could someone help me with some javascript code along with the actual password entry area and submit?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    That's easy to do.

    But it's also trivial for ANYBODY to simply look at your page and find the password.

    It's equally trivial for ANYBODY to simply look in your page, see what the URL in the link is and just go there and not bother even using the password.

    Passwords, hidden links, etc., etc., that are all done in HTML and/or JavaScript are as secure as an unlocked doorknob. Anybody smart enough to turn the knob gets in. So maybe you'll keep out the 1-year-olds, but a 2-year-old will turn the knob and walk right in.

    Are ALL the people who will be using your web page going to be 1-year-olds?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    It is possible to make a pretty secure login using Javascript provided that the password is the same for all users. The url name will be generated, and naturally only the url associated with the correct password will exist. Others will return a 404 error.


    Code:
    <form>
    <p>Enter The Password To View The Secret Page   <input type="text" name="Pswd" onBlur="OneWay(this)"></p>   
    <!-- The password is x  (case insensitive) -->
    </form>
    
    <script type = "text/javascript">
    function OneWay(S) {
    var pageName;
    var y = 2e50;
    var x = '0.'+ parseInt(S.value, 36);   // 36 is the radix
    for (var j=0; j<10; j++) {x = Math.tan(1+x+x*y%1)%1 }
    pageName = ((x+1)/2).toString(36).substring(2);
    pageName = pageName + '.html';
    alert (pageName);  // for testing
    //pageName =  "xvmrv5eoae0b.html";  // when password is "x"
    //window.location.href = pageName;  // uncomment for use
    }
    </script>
    If the password is cat then the url of your secret page will be n6qszy7z57xz.html
    If different users have different passwords then you must have a page for each user corresponding to that password.
    I expect that you realise that an actual password should be at least 8 characters.

    Another secure Javascript login may be found at Secure Login with javascript


    Quizmaster: Paris is bigger than Vienna. And Vienna is bigger than Rome. Which is the smallest?
    Contestant: Oh, I dunno. Paris?
    Last edited by Philip M; 07-19-2012 at 09:16 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How in the heck would I use that? There's no submit or anything. I don't want it to be secure, it's just a novelty. All I want it to do is redirect to the other page if the right "password" is submitted.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by Deathtracker View Post
    How in the heck would I use that? There's no submit or anything. I don't want it to be secure, it's just a novelty. All I want it to do is redirect to the other page if the right "password" is submitted.
    Oh, sorry I spoke.

    Did you not notice:-

    //window.location.href = pageName; // uncomment for use


    Or if you are not interested in security and are happy for anyone to access your page simply by using View Source (thus making the whole password thing childishly pointless):-

    Code:
    <input type = "password" id = "pwd" onblur = "redirectme(this)">
    
    <script type = "text/javascript">
    function redirectme(which) {
    var val = which.value;
    if (val == "therightpassword") {  // visible using View Source
    window.location.href = "mysecretpage.html"; // visible by using View Source
    }
    else {
    alert ("Invalid password");
    return false;
    }
    
    }
    
    </script>
    I think that will do for this topic.

    Code:
    var please = false;
    var thanks = false;
    if (!please && !thanks) {
    var interestLost = true;
    var moreHelp = 0;
    }

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, thanks for the help anyway, I came up with something simpler myself, that ends up scrambling the password. It's fine, it's not like I'm gonna be dealing with people that actually care about what's on the other page, it's really not that important.


  •  

    Posting Permissions

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