49 users online (0 members and 49 guests)  




  Results 1 to 4 of 4

Related

  1. password protection    Forum: Javascript Forum
    Replies: 2
  2. password protection help needed please    Forum: Javascript Forum
    Replies: 1
  3. password protection    Forum: Databases
    Replies: 7
  4. Replies: 1
  5. password protection?    Forum: HTML Forum
    Replies: 9
  1. #1
    JillianPaige
    JillianPaige's Avatar
    Guest

    Question Protection

    Um, I want to be able to password protect my page. Can anyone help me? Does anyone have any JavaScript?

  2. #2
    allstarr
    allstarr's Avatar
    Guest

    Post

    what kind of password script are you talking about?

  3. #3
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,441

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel

    Post

    javascript is not a very secure way of password protection. I would suggest a .htaccess depending on if you have the capabilities. Are you on a free host or are you on a paid server?

    Dave

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Post

    DO NOT USE JAVASCRIPT

    Any semi-decent JS programmer will be able to crack your encription by the simple reasoning that JS is Client-side, not server side. If you want security, use a server side technology like PHP.
    If you have PHP enabled on your host, then this script will password protect your page -



    <?php

    // Basic page Security header script

    // Check to see if $PHP_AUTH_USER already contains info

    if (!isset($PHP_AUTH_USER)) {

    // If empty, send header causing dialog box to appear

    header('WWW-Authenticate: Basic realm="My Password Protected Page"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Wrong Password!.';
    exit;

    } else if (isset($PHP_AUTH_USER)) {

    if (($PHP_AUTH_USER != "User") | | ($PHP_AUTH_PW != "secretword")) {

    header('WWW-Authenticate: Basic realm="My Password Protected Page"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required.';
    exit;

    } else {
    echo "
    <P><b>$PHP_AUTH_USER</b> logged in</p>
    ";
    }
    }
    ?>


    This script uses header commands. Therefore, in PHP, you have to make sure that the script starts at the very top of your page. No spaces, no blank lines at all. If there isd any blank lines, the header command does not work.

    Oh, and your page has to be called *.php instead of *.html.

    This script acts in a very similar way to .htaccess, using http-auth.

    Any questions, just post.

    ------------------
    QuietDean-



Tags for this Thread