Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Password Protect a Page Script Help

  1. #1
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Password Protect a Page Script Help

    Hi - I have this login script but I would like to have the prompt "incorrect password" with buttons to retry or cancel and only upon cancel would I like it redirect to "jpass2.htm"

    <SCRIPT language="JavaScript">
    <!--hide
    var password=prompt('Enter the password:','');
    var mypassword="cool";
    if (password==mypassword)
    {
    window.location="jex11.htm";
    }
    else
    {
    window.location="jpass2.htm";
    }
    //-->
    </SCRIPT>

    I'm new to javascript, sorry if this seems really simple.
    Last edited by isamarlow; 02-28-2007 at 09:22 PM.

  2. #2
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello dude ,

    Well heres probably what you want -

    <script>
    <!--
    function startpass() {
    var a = prompt("Enter the password:","Password here")
    if (a=="cool") {
    window.location="jex11.htm"}
    else {
    startpass2()}
    }

    function startpass2() {
    var cd = confirm("Incorrect Password.\nDo you wish to try again \?")
    if (cd==false) {window.location="jpass2.htm"}
    else {startpass()}
    }
    //-->
    </script>

    Well report back and your welcome

  3. #3
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Let's see anyone say that's invalid !!!

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Huh, that's one heck of a lot of overkill.
    Code:
    <script type="text/javascript">
      do {
        if(prompt("Enter the password:") === "cool")
          window.location.href = "jex11.htm";
      } while(confirm("Wrong password.  Try again?"));
      window.location.href = "jpass2.htm";
    </script>
    Note that this isn't at all secure, since anyone can look in your source and find the password, or even just find the URL and go there directly.
    If you want a more secure client-side solution, see my script, but your best bet will always be a server-side script.

    /EDIT: Cross-posted, sorry pcbrainbuster.
    Let's see anyone say that's invalid !!!
    It is: you're missing the type attribute on the <script> tag.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    And oh yeah this is only gaurenteed to work on ie i have no idea for the others

  6. #6
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Grrr twey is back !!!

  7. #7
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    And its not overkill !!!
    Its just the way i script !!!+!

  8. #8
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Have you considered doing this server side (ie with php)? It's much more secure, as no one get get you password by looking at the source.

    I could help you do that if you want.
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Even posting three times to respond is overkill.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    As your server-side script for a password you can use .htaccess

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
  •