/    Sign up×
Community /Pin to ProfileBookmark

HTML Password Access

Hi,

As a pretty basic web developer, I have been trying something new that I cannot seem to get working. Probably because I am such a beginner.

Here is what I am trying to acheive.

  • 1.

    On my index/main page. I want a button hyperlinked to a login page.

  • 2.

    User logs in with “Username” and “Password”, if OK re-directed. If not, then message to say “No Access”

  • Now, I was looking at ths scripy that I copied ([url]http://javascript.internet.com/passwords/multiple-users.html)[/url]. And although I understand the basics of what it is trying to do. I cannot get it to work the way I described above.

    Its probably because this is my first attemt at this, and I am missing something stupid.

    The password bit is purley so that I can limit basic to keen web users from easily accessing certain pages I want to create (nothing dodgy).

    Hope that someone can help.

    Cheers,

    Scots-Daywalker

    to post a comment
    HTML

    4 Comments(s)

    Copy linkTweet thisAlerts:
    @scotsdaywalkerauthorJun 08.2006 — Sorry, link never copied properly "http://javascript.internet.com/passwords/multiple-users.html"
    Copy linkTweet thisAlerts:
    @the_treeJun 08.2006 — You should never attempt any kind of authentication on the client-side, your letting users download the passwords! It's crazy.

    If your host will allow it, use .htaccess or some form of server-side-scripting. Check what your host supports in that vein and we'll help you out.
    Copy linkTweet thisAlerts:
    @scotsdaywalkerauthorJun 08.2006 — I am just trying to create a way so that a web user accessing my site. Would have to use a username and password (given by me), to access certain pages.

    Was just looking for a basic way of doing this. Was not too sure what you meant by "letting users download the passwords"?.

    But sounds like it might be much more that I'm able to do, or wanted to do. It would have been a "Nice to Have", but not essential.

    Cheers,

    Scotsdaywalker.
    Copy linkTweet thisAlerts:
    @the_treeJun 08.2006 — The script that you linked to, runs on the visitors computer (we call this client-side), this means that the entire script, including the passwords, are downloaded by the visitor before the scripts do anything. Anyone with any idea how to use thier browser will then be able to the paswords quite quickly (we call this stupid).

    The standard, sensible way, is to have a script running on the server (we call this server-side), so that the nosy visitor need never see the details. And there is a squillion different languages that can do this but it depends on what server-side scripting your host supports. Even better would be if your host supports '.htaccess' and '.htpassword'.

    It's not really difficult, especially when you can get most of the hard work done for you right here.


    [b]Edit[/b]

    For examples sake, here is what it would look like in PHP (a most excellent server-side-scripting language):[COLOR=Blue]<?php
    // change these two variables.

    $username = 'Username';
    $password = 'Password';

    if ($PHP_AUTH_USER != $username or $PHP_AUTH_PW != $password){
    header('WWW-Authenticate: Basic realm="Protected Page"');
    header('HTTP/1.0 401 Unauthorized');

    // Firstly, for those who *haven't* already entered the correct username + password
    ?>[/COLOR]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Unauthorised</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <h1>Unauthorised</h1>
    <p>You haven't entered a correct password, go away.</p>
    </body>
    </html>
    [COLOR=Blue]<?php }else{
    // This section is for those who *have* entered the correct username + password
    ?>[/COLOR]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Authorised</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <h1>Authorised</h1>
    <p>You've entered the correct pasword, well done.</p>
    <p>Content, content, content.</p>
    </body>
    </html>
    [COLOR=Blue]<?php } ?>[/COLOR]
    ×

    Success!

    Help @scotsdaywalker spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...