How do you password protect a webpage?

I want to set up one page on my website that will be a private place for my thoughts. There are some people I'd be willing to share this page with, but I don't want everyone to have access to it. What is the html code to protect a webpage so that only those with the right password can access it?

Comments

  • It depends on if your webpages will be located on a Unix (Linux) server or a Windows 2000 (IIS server).

    If its on a IIS server, then a code as simple as this will do on the top of the page u want protected

    <%If session("user") = "" Then response.redirect("login.asp")%>

    A good example of this way is if you try to click goto http://sharpnetwork.net/?download you get redirected to login.asp if you aren't logged in.

    To get the Session("user") variable set, you create a form

    <form>

    <input name=password>

    <input type=submit>

    </form>

    <%If request("password") = "mypassword" Then

    Session("user") = "hello"

    Response.redirect("secretpage.asp")

    End If%>

    If you're using a Linux server, then you can add a file called .htaccess (google .htaccess for more info and how to) to the directory with the protected page in it. When someone goes to that page, it popup that box (Basic Auth box) that you may have seen on some sites.

    If all of these are complicated, then the easiest way is to stick a java script on it. You can make it as simple as to popup a javabox and ask a password. The problem with that, is that all the person has to do is right click the page and View Source and can see the password (because java is client side, whereas .asp is server side). But I think I have seen some java tricks to where you can use some fancy encoding in the script to where you can't see the password in the source code. I would try to google java password protect for those examples.

  • try setting up the page as a normal text document or PDF file then just either secure the page as you could with your HTM generator program (frontpage, dreamweaver etc) your page if in the form of htm would need to be on an https server for the best results. but FTP would work just as well. and you can host your ftp page from your own home computer as if it is just a journal you will be able to set up who has access to the page with the use of an FTP server program such as that included in netserversuite. if you own the server you own the pages and who can access them and who can remotley modify the pages.

    and without ftp for your webserver no one can make changes to your webpages if you do not let them have access to them.

    when setting up a server never use the user name amin or similar. as that is the first id that hackers go for to attempt ti hack in to your server.

    also use strong passwords.

    you could also try placing a subfolder that only you know about that does not have any links from your home page so it's path is well hidden and only the most determined hackers would find it.

    but an ftp server would be the best option for a personal journal that only you want access to or you want a strictly limited access.

    ftp servers have the advantage of being able to set up to allow anyone (anonymose) or to only allow those you give permission to manually. you can set each user to have access to a different folder or just a file the site also has the advantage of setting up a seperate username and password in any format you as administrator set up. and once set by you can not be changed by the end user.

    the advantages go on, but io can't now.

    so good luck and i hope you have a good new year.

  • Not an easy one, do i got 10 points for best answer?>

    HU?

    I thought I heard a yes :-)

    Ok,its not an HTML code, you need to do the following, it works great! I am assuming you know how to ftp into your site....

    Here ya go for my 10 points:

    Instead of step by step, I decided to create for you a script, just change the username and password in it..... I will tell you how....

    <script language="javascript">

    <!--//

    /*This Script allows people to enter by using a form that asks for a

    UserID and Password*/

    function pasuser(form) {

    if (form.id.value=="userID") {

    if (form.pass.value=="password") {

    location="page2.html"

    } else {

    alert("Invalid Password")

    }

    } else { alert("Invalid UserID")

    }

    }

    //-->

    </script>

    <center>

    <table bgcolor="white" cellpadding="12" border="1">

    <tr><td colspan="2"><center><h1><i><b>Login

    Area</b></i></h1></center></td></tr>

    <tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="login"><input

    name="id" type="text"></td></tr>

    <tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"

    type="password"></td></tr>

    <tr><td><center><input type="button" value="Login"

    onClick="pasuser(this.form)"></center></td><td><center><br><input

    type="Reset"></form></td></tr></table></center>

    ENDS ABOVE .....

    This script should only take you a few minutes to setup. The only thing you need to do is edit the username, password, and the page the person will direct to when the correct password is entered correctly.

    First, copy the code in the above box and paste it into an HTML web page. The page could be named whatever you'd like: index.html for example.

    Look for a line in the script that reads...

    if (form.id.value=="userID") {

    This is the username. Change "userID" it to whatever username you'd like to use.

    Now look for a line in the script that reads...

    if (form.pass.value=="password") {

    Change "password" to the one you'd like to use.

    Now look for a line that says...

    location="page2.html"

    This is the URL of the page that the person will be directed to when they enter the correct password. Keep in mind this assume that the page is located in the same directory of the page the password script is on. You may have to edit the path accordingly. If you're not sure, just put the complete URL of the page here. Example: http://www.yourdomain.com/file.html

    The next step is optional. This is only if you want to alter the error messages that are displayed when the username or password is not entered correctly. If you don't change anything in these lines, the default error messages will display.

    Look for a line that says...

    alert("Invalid Password")

    You can change "Invalid Password" to whatever message you'd like. For example, you can make it say, "The password you entered is incorrect. Please try again."

    You can also do the same to the user Invalid ID section. Look for the line...

    } else { alert("Invalid UserID")

    Change "Invalid UserID" to whatever message you'd like to display when the username is incorrect.

    Congratulations! You have just password protected a web page.

    Kosher1

  • For diverse consumer as you suggested, the main suitable way could be to setup a database (mySQL or regardless of) and code the region to allow consumers to sign in and examine in to get right of entry to the region.

Sign In or Register to comment.