Wrox Programmer Forums
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Dreamweaver (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2004, 11:00 AM
Authorized User
 
Join Date: Aug 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning D.W.2004 SoccerSite

Hi,
I have a problem with FileSystemObject,page 332 onwards.
Up to this point my Soccersite has worked fine. However, now that I have type in the code (page 333/334) I cannot login. I created the users.txt and placed it in the tools folder but the login page does not recognize the username and password (I do type them in correctly) Perhaps you will check my code out, (enclosed) and advise.

Regards
Terry.s

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% 
Dim sErrorMessage
Dim sReferrer
If Request.Form("txtReferrer") = "" Then
sReferrer =Request.QueryString("accessdenied")
Else
sReferrer = Request.Form("txtReferrer")
End If
If sReferrer = "" Then
sReferrer = "Admin/admin.asp"
End If
If Request.Form("txtUserName") <> "" And _
      Request.Form("txtPassword") <> "" Then
Const ForReading = 1
Dim oFileSystemObject
Dim oTextStream
Dim sFileLocation
Dim sTempString
Dim arrTemp
Dim bUserFound
If Request.Form("btnLogin") <> "" Then
sFileLocation = Server.MapPath("Tools/users.txt")
' Create an instance of the FileSystemObject
Set oFileSystemObject =  Server. CreateObject("Scripting.FileSystemObject")
' Create a reference to our text file so we can read from it
Set oTextStream = oFileSystemObject. OpenTextFile(sFileLocation, ForReading)
' Read each line until we reach the end of the file
Do While (Not oTextStream.AtEndOfStream = True)
' Read a line
sTempString = oTextStream.ReadLine()

' If the line contains text
If Len(sTempString) > 0 Then
' The line should hold the username and password separated by a tab
' Split the line based on a tab, so we get the username and password
' in two separate array elements
arrTemp = Split (sTempString, vbTab)
If IsArray(arrTemp) Then
' An UBound of 1 means two elements in the array, the username
' and the password. If we haven't found both, we do not continue

If UBound(arrTemp) = 1 Then
' Compare array elements with username and password
If arrTemp (0) = Request.Form("txtUserName") And _
   arrTemp (1) = Request.Form("txtPassword") Then
   bUserFound = True
   Exit Do
      End If
    End If
    End If
    End if
   Loop
   ' Close our textstream and clean up our objects
   oTextStream. Close
   Set oTextStream = Nothing
   Set oFileSystemObject = Nothing
   If bUserFound = True Then
   Session ("MM_Username") = Request.Form("txtUserName")
   Response.Redirect (sReferrer)
   Else
   sErrorMessage = "<span class ="" clsErrorMessage""><br>" & _
      "Login failed. Please type  a valid username and password</span>"
      End If
      End If
End If
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>GlobalSoccerEvents.com - Your Source for Soccer Events Around The Globe</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>


<link href="Styles/mainStyles.css" rel="stylesheet" type="text/css">
</head>

<body><table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="Images/logo.gif" width="257" height="58"></td>
    <td><table border="0" align="right" cellpadding="0" cellspacing="0">
  <tr>
    <td><a href="home.asp" id="home">Home</a></td>
    <td>   </td>
    <td><a href="events.asp" id="events">Events</a></td>
    <td>   </td>
    <td><a href="mysite.asp" id="mysite">My Site</a></td>
    <td>   </td>
    <td><a href="login.asp" id="login">Login</a></td>
     </tr>
</table>
</td>
  </tr>
</table>
<br>
<script language="JavaScript" type="text/javascript">
var sPageName='<%=Request.ServerVariables("SCRIPT_NAME")%>';
sPageName = sPageName.substr(sPageName.lastIndexOf('/') + 1). toLowerCase();
sPageName = sPageName.substr(0, sPageName.lastIndexOf('.'));
if (document. getElementById(sPageName)
{
document.getElmentById(sPageName). style.fontWeight = 'Bold';
docment.getElementById(sPageName.stylefontSize = '14'}
 </script><table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><h2>Login to GlobalSoccerEvents.com </h2></td>
  </tr>
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="1" bgcolor="#000000">
        <tr>
          <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="8">
              <tr>
                <td>Please type  your username and password and click the "Login" button
                <%=sErrorMessage%>
                </td>
              </tr>
              <tr>

                  <td width="100%" bgcolor="#CCCCCC" colspan="2">
                  <form action="login.asp" method="post" name="frmLogin" onSubmit="MM_validateForm('txtUserName','','R','txtPassword','','R');return document.MM_returnValue">
                    <p>Username<br>
                        <input name="txtUserName" type="text" class="clsTextInput" id="txtUserName" style="width: 150px;">
                    </p>
                    <p>Password<br>
                        <input name="txtPassword" type="password"class="clsTextInput"  id="txtPassword"style ="width: 150px;">
                    </p>
                    <p>
                      <input name="btnLogin" type="submit" id="btnLogin" value="Login">
                  </p>
                <input name="txtReferrer" type="hidden" value="<%=sReferrer%>"></form>
                </td>
              </tr>
          </table></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td align="center"><br>
    <br>
    <br>
    <br>
    <br>
    </a> </td>
  </tr>
</table>
</body>
</html>
 
Old October 22nd, 2004, 01:22 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Terry,

Do you get an error, or does it just not work? Do you have Anti Virus software that blocks you from using the FSO?

Also, in what folder is this page located? Is it at the same level as the Tools folder? That is, will Server.MapPath("Tools........ get the right results?

This to test:

Use Response.Write("Test 1") , Test 2 etc at important locations so you can see what path the code follows. That also allows you to "trace" the value of variables, read lines etc.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Burger Queen by Placebo (Track 12 from the album: Without You I'm Nothing) What's This?
 
Old October 23rd, 2004, 06:04 AM
Authorized User
 
Join Date: Aug 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
Many thanks for your prompt reply.
The page will load into the browser but after typing in the username and password, the message, "invalid username and password ..." appears. I have tried all three of my usernames and passwords.

I have switched off my virus checker , but with same result.
All folders are at the correct level The page work perfectly before writing in the code I've already sent.
How do I test as you suggested? Step by step please.

Regards

Terry s


 
Old October 23rd, 2004, 08:40 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Like I said, use Use Response.Write("Test 1") to find out how your code runs.,

For example:

Do While (Not oTextStream.AtEndOfStream = True)
Response.Write("About to read Line")
' Read a line
sTempString = oTextStream.ReadLine()

Response.Write("Line is " & sTempString )

' If the line contains text
If Len(sTempString) > 0 Then
' The line should hold the username and password separated by a tab
' Split the line based on a tab, so we get the username and password
' in two separate array elements
arrTemp = Split (sTempString, vbTab)
If IsArray(arrTemp) Then
' An UBound of 1 means two elements in the array, the username
' and the password. If we haven't found both, we do not continue

If UBound(arrTemp) = 1 Then
' Compare array elements with username and password


Etc etc. This way you can see what happens inside the code, and what If or Else statements are executed. This can help you track down the problem.

Are you aware your password is case sensitive??

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Frantic by Metallica (From the album: St.Anger) What's This?
 
Old October 25th, 2004, 12:04 PM
Authorized User
 
Join Date: Aug 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
 Well I've done as you requested, testing the code ( as well as I can)
and can get the usernames and passwords to show in the browser when I add the line Reponse.Write("test" & sStringTemp) at line 41 after If Isarray(arrTemp) Then
 But after that, any further tests do not show any results in the browser.
 I am aware that the names are case sensitive.
 I must admit I'm foundering with the tests as I not to sure what is going on. If I open Admin or Popular first page I still get referred to the login page.
so some thing s are working.
I've checked and rechecked the code and I.m sure i have type it in correctly.
 Are any other of your clients having the same troubles?


Regards

Terry s

 
Old October 25th, 2004, 02:21 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

How did you separate the user name from the password in the text file? Are you sure you used a Tab character and not a space?

This is the first time this code shows up in this forum, so either other people didn't have an issue with it, or they never brought it to this forum....

Check out the text file and let me know if that helps.
If all else fails, can you send me a zipped version of the login page and the password file? be sure to remove any sensitive info from that file.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Firestarter by The Prodigy (Track 8 from the album: The Fat Of The Land) What's This?
 
Old October 26th, 2004, 10:58 AM
Authorized User
 
Join Date: Aug 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Your suggestion re tab was correct, I must have used the space bar. Many thanks once again for your help.

I have an unrelated query. When trying to sort out the above I checked the code in admin.asp and noted the following.

On page 325 of the book "restrict access to page" Asp code is added to the top of the page.

On page 326 in "How it works" it explains how the code works. However the code loaded,incudes line 8,
Code:
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
is different to the book. The word "false" is replaced with the word "true"
My page works okay, so which is correct ??

Regards

Terry s


 
Old October 26th, 2004, 03:25 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

AFAICS, you didn't follow the instructions correctly.
The code you are describing will be added to the page when you choose Username, password and access level instead of just Username and password.

Is that correct? Did you select the second radio on the Restrict Access To Page dialog?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Daddy by KoRn (Track 12 from the album: KoRn) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning MX 2004 pg. 221 Beth Ellen Dreamweaver (all versions) 3 May 14th, 2005 06:12 AM
Beginning Dreamweaver MX 2004 - Page 73 ColinS Dreamweaver (all versions) 4 May 14th, 2005 02:01 AM
Beginning Dreamweaver 2004 Building Blocks terry s Dreamweaver (all versions) 1 February 12th, 2005 03:59 PM
Beginning Dreamweaver MX 2004? stephman Dreamweaver (all versions) 6 January 22nd, 2004 05:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.