Solved

Password For Page

Posted on 2003-11-14
8
420 Views
Last Modified: 2010-04-06
I Am Making A Site In FrontPage
I Want To Make A Password For A Page
So When I Clicked On A Button I Must Enter The Correct Password
For Enabling A Link

How Can I Make IT
Thanks Alot
0
Comment
Question by:waelolabi
8 Comments
 
LVL 1

Expert Comment

by:Depeche_Mode
ID: 9752410
Do you want to store the password or details in a web page ?


=================
Long Live the Penguin
=================



Cheers
******
0
 
LVL 1

Expert Comment

by:Depeche_Mode
ID: 9752416
Hi,

Assuming that you need to store the values collected :-

I have two pages here which do exactly what u have asked for .

The database name has to be enterd by you.

The code assumes the table name to be "Usernames" (you can change this.)

The table should have the following fields in it.

Username
Password
Email
FirstName
LastName
Gender
AIM
MSN

After creating the table cut and copy the following code.....

There are two pages ...the first page takes the data from teh user using a form and the next does some error checking including verifying the password and checking for duplicate users ....

and updates the table in the database

*************************************
FIRST PAGE CONTAINING THE FORM
*************************************



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Adding a User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<p align="center"><i><font face="Haettenschweiler" size="5" color="#800080">&nbsp;</font></i>

</font><b><font face="Bookman Old Style" color="#800080" size="6">Adding a User </font></b></i></p>
<p align="center">&nbsp;</p>
<p align="center"> <br>
&nbsp;</p>

<form method="POST" action="verify_user.asp?">

<p align="center">
  <table width="758" border="0">
    <tr>
      <td height="30"><font color="#FF0000">*</font></td>
      <td><em><strong>
      <font face="Geneva, Arial, Helvetica, sans-serif" size="2">Please Enter a
      First Name</font></strong></em></td>
      <td>&nbsp;</td>
      <td>        <font size="2">
          <input type="text" name="first_name" size="20"></font></td>
    </tr>
    <tr>
      <td height="30"><font color="#FF0000">*</font></td>
      <td><em><strong>
      <font face="Geneva, Arial, Helvetica, sans-serif" size="2">Please Enter a
      Last Name</font></strong></em></td>
      <td>&nbsp;</td>
      <td>        <font size="2">
          <input type="text" name="last_name" size="20"></font></td>
    </tr>
    <tr>
      <td height="30"><div align="center"><font color="#FF0000">*</font></div></td>
      <td><div align="left"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><strong><em>Please Specify a User Name </em></strong></font></div></td>
      <td><div align="center"><font size="2"><strong>:-</strong></font></div></td>
      <td>        <div align="left"><font size="2">
          <input type="text" name="user_name" size="20">      
      </font></div></td>
    </tr>
    <tr>
      <td height="31"><div align="center"><font color="#FF0000">*</font></div></td>
      <td><div align="left"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><strong><em>Please Specify a Password for the user </em></strong></font></div></td>
      <td><div align="center"><font size="2"><strong>:-</strong></font></div></td>
      <td>        <div align="left"><font size="2">
          <input type="password" name="password" size="20">      
      </font></div></td>
    </tr>
    <tr>
      <td height="31"><div align="center"><font color="#FF0000">*</font></div></td>
      <td><div align="left"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><strong><em>Please Re-Confirm the Password </em></strong></font></div></td>
      <td><div align="center"><font size="2"><strong>:-</strong></font></div></td>
      <td>        <div align="left"><font size="2">
          <input type="password" name="confirm_password" size="20">      
      </font></div></td>
    </tr>
    <tr>
      <td height="58"><div align="center"><font color="#FF0000">*</font></div></td>
      <td><p align="left"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><strong><em>Please Enter an email - address for the User</em></strong></font></p>
      </td>
      <td><div align="center"><font size="2"><strong>:-</strong></font></div></td>
      <td>        <div align="left"><font size="2">
          <input type="text" name="email" size="20">      
      </font></div></td>
    </tr>
    <tr>
      <td height="58">&nbsp;</td>
      <td><em><strong>
      <font face="Geneva, Arial, Helvetica, sans-serif" size="2">Please Enter
      your Gender</font></strong></em></td>
      <td><strong><font size="2">:-</font></strong></td>
      <td>        <font size="2">
          <input type="text" name="gender" size="20"></font></td>
    </tr>
    <tr>
      <td height="58">&nbsp;</td>
      <td><em><strong>
      <font face="Geneva, Arial, Helvetica, sans-serif" size="2">Please enter
      your AIM Id</font></strong></em></td>
      <td><strong><font size="2">:-</font></strong></td>
      <td>        <font size="2">
          <input type="text" name="aim" size="20"></font></td>
    </tr>
    <tr>
      <td height="58">&nbsp;</td>
      <td><em><strong>
      <font face="Geneva, Arial, Helvetica, sans-serif" size="2">Please Enter
      your MSN Id</font></strong></em></td>
      <td><strong><font size="2">:-</font></strong></td>
      <td>        <font size="2">
          <input type="text" name="msn" size="20"></font></td>
    </tr>
    <tr>
      <td height="58">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>        &nbsp;</td>
    </tr>
  </table>
</p>

<p>&nbsp;</p>
<p><center>
<input type="submit" >
</center>
</p>
<p><font color="#0033CC"><em><font color="#FF0000">Note :-</font> Fields marked with <font color="#FF0000">*</font> are required fields. A valid email address is required for successfully adding the user. </em></font></p>
</form>


</body>
</html>


***************************************************
END OF FIRST PAGE
****************************************************


***************************************************
START OF SECOND PAGE
***************************************************


<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Verify Admin</title>
</head>

<body>


<%


*******************************************
ENTER YOUR DATABASE PATH NAME HERE
*******************************************

Session("DatabasePath") = ".....UserName.mdb"


Dim DataConnection, cmdDC, RecordSet
Dim RecordToEdit, Updated


Set DataConnection = Server.CreateObject("ADODB.Connection")
DataConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Session("DatabasePath") & ";"




'----------------------------------------------------------------------
'----------------------------------------------------------------------

' START CODE FOR ADDING A NEW USER

'----------------------------------------------------------------------
'----------------------------------------------------------------------



'----------------------------------------------------------------------
'----------------------------------------------------------------------

' START Collecting data from the form

'----------------------------------------------------------------------
'----------------------------------------------------------------------

firstname = Request.Form("first_name")
lastname = Request.Form("last_name")
username = Request.Form("user_name")
password = Request.Form("password")
confirm_password = Request.Form("confirm_password")
email = Request.Form("email")
gender = Request.Form("gender")
aim = Request.Form("aim")
msn = Request.Form("msn")




flag_blank = 0

'========================================================================
'Start of checking email address or username or any of the fields are left blank
'========================================================================

if(username = "" OR email = "" OR firstname = "" OR lastname = "" OR gender = "" OR aim = "" OR msn = "") Then

     flag_blank = 1
     


End if

'========================================================================
'End of checking email address or username is blank before putting them in an array
'========================================================================
     




'----------------------------------------------------------------------
'----------------------------------------------------------------------

' End Collecting data from the form

'----------------------------------------------------------------------
'----------------------------------------------------------------------


'----------------------------------------------------------------------
'----------------------------------------------------------------------

' Checking if the user exists
'----------------------------------------------------------------------
'----------------------------------------------------------------------

                             
                              '===========================================================
                              'Start of loop which checks if user exists in the database
                              '===========================================================
                             
                              if(flag_blank = 0) Then
                             
                             
                             
                              '===========================================================
                              ' Start of loop for multiple users
                              '===========================================================
                             
                             
                             
                             
                   
                              Set Cm_user = Server.CreateObject("ADODB.Command")
                              Cm_user.ActiveConnection = DataConnection
                             
                              SQL_user = "SELECT Username FROM UserNames WHERE Username ='" & user_name & "'"
                               
                             
                              Cm_user.CommandText = SQL_user
                             
                              Cm_user.CommandType = 1
                             
                             
                              Set Rs_user = Cm_user.Execute
                             
                              Cm_user.CommandText = SQL_user
                             
                              Set RS_user = Server.CreateObject("ADODB.Recordset")
                               
                              RS_user.Open Cm_user, , 0, 2
                             
                             

                             
                                   if(RS_user.eof) Then
                             
                                                       
                                   Else
                             
                                                  dup_user_flag = 1
                                   
                                                  Response.Write("<p><i><b><font size='4' face='Monotype Corsiva' color='#FF0000'>")
                                                  Response.Write("<br><br>")
                                                  Response.Write("Sorry!! An error was encountered.")
                                                  Response.Write("<br><br>")
                                                  Response.Write("The user name specified already exists. Please go back and choose another user name.")
                                                  Response.Write("The user name is ") & user_array(i)
                                                  Response.Write("<br><br>")
                                                  Response.Write("</font></b></i></p>")

                             
                                   End if
                             
                             
                              Next
                             
                              '===========================================================
                              ' End of loop for multiple users
                              '===========================================================

                         
                              End if
                             
                              '=========================================================================
                              'Start of loop flag_null flag which checks for null emails and usernames
                              '=========================================================================


                              '===================================================================
                              'Start of loop for checking the password equals the confirm password
                              '===================================================================
                             
                              if(confirm_password = password) Then

                                                  password_flag = 0

                              Else

                                                  password_flag = 1

                                                  Response.Write("<p><i><b><font size='4' face='Monotype Corsiva' color='#FF0000'>")
                                                  Response.Write("<br><br>")
                                                  Response.Write("Sorry!! An error was encountered.")
                                                  Response.Write("<br><br>")
                                                  Response.Write("The password does not match the confirmed password. Please go back and re - enter your password.")
                                                  Response.Write("<br><br>")
                                                  Response.Write("</font></b></i></p>")


                              End if
                             
                              '===================================================================
                              'Start of loop for checking the password equals the confirm password
                              '===================================================================

if(password_flag = 0 AND dup_user_flag = 0 AND flag_blank = 0) Then


'=================================
'start of loop for multiple users
'=================================


Set Cm = Server.CreateObject("ADODB.Command")
Cm.ActiveConnection = DataConnection


SQL_add_user = "SELECT * FROM Usernames"
 

Cm.CommandText = SQL_add_user

Cm.CommandType = 1


Set Rs_user = Cm.Execute

Cm.CommandText = SQL_add_user

  Set RS_user = Server.CreateObject("ADODB.Recordset")
 
  RS_user.Open Cm, , 0, 2

  RS_user.AddNew

  RS_user("Username") = username
  RS_user("Password") = password
  RS_user("Email") = email
  RS_user("FirstName") = firstname
  RS_user("LastName") = lastname
  RS_user("Gender") = gender
  RS_user("AIM") = aim
  RS_user("MSN") = msn

 
 
 
  RS_user.Update






'=======================================
' End of loop for adding the new user
'=======================================



%>
</body>

</html>


***************************************************
END OF SECOND PAGE
***************************************************


Hope this helps


===============
Long Live the Penguin
===============


Cheers
******
0
 
LVL 15

Expert Comment

by:Daydreams
ID: 9753784
Put the following code in the body of your page.To configure the password, change letmein. To change the password protected page (the target page), change protectpage.html.
From: http://javascriptkit.com/script/cut10.shtml

<SCRIPT>
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter Your Password',' ');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1.toLowerCase() == "letmein") {
alert('You Got it Right!');
window.open('protectpage.html');
break;
}
testV+=1;
var pass1 =
prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return " ";
}
</SCRIPT>
<CENTER>
<FORM>
<input type="button" value="Enter Protected Area" onClick="passWord()">
</FORM>
</CENTER>
0
 
LVL 8

Expert Comment

by:MusicMan
ID: 9753987
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:Depeche_Mode
ID: 9757358
Please close the question and award the necessary points if you feel that your problem has been solved.

Thanks.


==============
Long Live the Penguin
==============


Cheers
******
0
 
LVL 8

Expert Comment

by:MusicMan
ID: 9758161
Give him a chance - it's only been 2 days!!!!
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9766510
simple NON SECURE Javascript way


<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function login(){
      var myPW = "notSecure";
      if(document.forms[0].pw.value != myPW){
            document.write("Wrong Password. Press your browser back button and try again");
      } else {
            location.replace("http://yoursite/yourNotSecurePage.html");
            }
      }
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="text" name="pw">
<input type="button" name="btnSubmit" value="Login" onclick="login();">
</form>
</body>
</html>

0
 
LVL 1

Accepted Solution

by:
cj_nepenthe earned 25 total points
ID: 9783988

Hi,

Here's a very simple way to add password protection to a page.  You'll need to add this bit of JavaScript to you page's HTML source:

Please enter the password:
<input name="password" type="password">
<input type="button" value="Go" onclick="location.href=password.value+'.htm'">

When the user clicks the Go button, the page will redirect to [password].htm, where [password] is what the user entered.  So, for example, call your protected page "p455w0rd.htm", then the user will have to enter the password "p455w0rd" to get to it.

This isn't really proper password protection, but it's great as a quick and easy solution.
If you need something a bit more secure and robust, then you'll need to send a password over SSL to an authentication script on the server, which can then control access to your page.
Alternatively, try looking at using Windows (NTLM) permissions if you're using IIS, or setting up a .htaccess file if you're on Apache.

Good luck!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 32
PHP radio buttons with email not sending 24 95
Create and populate iFrame onClick of a button? 1 64
Swiper slider stops between pages 11 45
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to count occurrences of each item in an array.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now