Password routine

Discussion in 'ASP.NET / ASP.NET Core' started by johnabrown, May 10, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I am trying to implement password protection to certain pages. I have copied a routine from htmlgoodies.com and it works until a certain point. There is a file named engine.asp that contains the following code:




    <NOBR><%@ LANGUAGE="VBSCRIPT" %>

    <%
    ' Connects and opens the text file
    ' DATA FORMAT IN TEXT FILE= "username<SPACE>password"

    Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
    </NOBR><NOBR> 'Set MyTextFile=MyFileObject.OpenTextFile(Server.MapPath("\path\path\path\path") &amp; "\passwords.txt")
    Set MyTextFile=MyFileObject.OpenTextFile(Server.MapPath("\_database") &amp; "\passwords.txt")

    ' Scan the text file to determine if the user is legal
    WHILE NOT MyTextFile.AtEndOfStream
    ' If username and password found
    IF MyTextFile.ReadLine = Request.form("username") &amp; " " &amp; Request.form("password") THEN
    ' Close the text file
    MyTextFile.Close
    ' Go to login success page
    Session("GoBack")=Request.ServerVariables("SCRIPT_NAME")
    Response.Redirect "inyougo.asp"
    Response.end
    END IF
    WEND

    ' Close the text file
    MyTextFile.Close
    ' Go to error page if login unsuccessful
    Session("GoBack")=Request.ServerVariables("SCRIPT_NAME")
    Response.Redirect "invalid.asp"
    Response.end

    %> </NOBR>


    <NOBR>By commenting out most of the code, I think I have found that the offending code is:</NOBR>


    <NOBR>Set MyTextFile=MyFileObject.OpenTextFile(Server.MapPath("\_database") &amp; "\passwords.txt")
    </NOBR>


    <NOBR>Possibly my problem is that I have the incorrect path. The temporary address that I have is </NOBR>


    <NOBR>http://waterworksl.web127.discountasp.net/</NOBR>


    <NOBR>If I want to keep the password.txt file in the _database subdirectory, what would be the correct syntax </NOBR>


    <NOBR>for that line?</NOBR>


    <NOBR>Thanks, John Brown</NOBR>


    <NOBR></NOBR>
     
  2. It works until a certain point? Can you please provide more information on this?

    The server.mappath at the bottom looks correct.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  3. <NOBR>If I comment most of the code out as below, it will run without error.</NOBR>


    <NOBR><%@ LANGUAGE="VBSCRIPT" %>

    <%
    ' Connects and opens the text file
    ' DATA FORMAT IN TEXT FILE= "username<SPACE>password"

    Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
    </NOBR><NOBR> 'Set MyTextFile=MyFileObject.OpenTextFile(Server.MapPath("\path\path\path\path") &amp; "\passwords.txt")
    'Set MyTextFile=MyFileObject.OpenTextFile(Server.MapPath("\_database") &amp; "\passwords.txt")

    '' Scan the text file to determine if the user is legal
    'WHILE NOT MyTextFile.AtEndOfStream
    ' If username and password found
    ' IF MyTextFile.ReadLine = Request.form("username") &amp; " " &amp; Request.form("password") THEN
    ' ' Close the text file
    ' MyTextFile.Close
    ' ' Go to login success page
    ' Session("GoBack")=Request.ServerVariables("SCRIPT_NAME")
    ' Response.Redirect "inyougo.asp"
    ' Response.end
    ' END IF
    'WEND

    '' Close the text file
    'MyTextFile.Close
    '' Go to error page if login unsuccessful
    'Session("GoBack")=Request.ServerVariables("SCRIPT_NAME")
    Response.Redirect "invalid.asp"
    Response.end

    %> </NOBR>
    If I run the code as shown in the original post, I get the "page cannot be displayed" error when engine.asp is referenced/called.

    Thanks, John
     
  4. http://www.waterworkslms.comFrom initial page click >Contact Us and on the contact page click on the Downloads link. user = admin, password = 1234 should be OK.


    Thanks, John


    give me just a few minutes to get the erring code back up. I was doing trial and error and removed all the calls to Server.CreateObject,Server.MapPath, etc and just hardcoded the username requirments and it did work. So I have learned something.


    This works:





    <%@ LANGUAGE="VBSCRIPT" %>


    <%
    IF Request.form("username") = "jab" THEN
    ' Go to login success page
    Session("GoBack")=Request.ServerVariables("SCRIPT_NAME")
    Response.Redirect "inyougo.asp"
    Response.end
    END IF


    Session("GoBack")=Request.ServerVariables("SCRIPT_NAME")
    Response.Redirect "invalid.asp"
    Response.end


    %>
     
  5. I'm getting the following error message...




    Microsoft VBScript compilation error '800a03ee'


    Expected ')'


    /engine.asp, line 9 Set MyTextFile=MyFileObject.OpenTextFile(Server.MapPath("\_database\passwords.txt")
    -----------------------------------------------------------------------------------^


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  6. That works! Thank you very much.
    </o:p>
    I am new at web development and ASP. I can now see that I am not using the proper tools because you were able to see my error and I was not. All I got was ?not able to display page? error from internet explorer.
    </o:p>
    I develop applications for desktop and local network computers. I use VB6, ADO, ActiveReports, etc. My daughter ?created a website? (static) for me using MacroMedia? I have figured out how to make small changes utilizing html code. When I needed dynamic features (which customer, prospect logged in, do they have authority to download, etc.) I decided to do it manually using Ultra Edit and CuteFTP and ADO code. I needed password protection and I found some sample ADO code at HTMLgoodies. I copied the code to the suggested files, made necessary code changes in UltraEdit and uploaded it to my new site at DiscountAsp. It would not work and I could not tell what the error was. You were helpful and told me what it was.
    </o:p>
    Now I have these questions. (it is very limiting to be a newbe)
    1) I provided simple ASP code to your server. DiscountAsp server runs some version of Microsoft IIS that compiles / interprets my ASP code and then runs it. Is that about right?
    2) DiscountAsp has forums for Classic ASP, ASP.Net, ASP.Net 2.0. How can I know what version of ASP the code I provided is?
    3) Is Classic ASP the same version / era as VB6?
    4) It would be very useful to have intelli-sense / auto complete when writing this code. Some form of error checking might have helped me with the problem you solved. Is there a Microsoft IDE for ADO and VB that comes with Visual Studio?
    </o:p>
    Thanks, John Brown
    </o:p>
     
  7. Oops, pervious post should have said for 4)

    4) It would be very useful to have intelli-sense / auto complete when writing this code. Some form of error checking might have helped me with the problem you solved. Is there a Microsoft IDE for ASP (ASP not ADO)and VB that comes with Visual Studio?

    Thanks Again, John Brown
     
  8. Ahh Internet Explorer has this thing called "Friendly Error Messages". You need to go to Tools > Options > Advanced and turn this off to see the real error message.


    *thanks IE*



    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     


  9. 1) Yes, IIS6.


    2) Classic is asp, the extension will end in '.asp'. You can run classic asp and asp.net on the same site. Asp.net 1.x and Asp.net 2.0 can be swiched in the control panel (you select). If you havent changed this, you are setup for Asp.net 1.x.


    3) VB6 is compiled code. Same era I guess. A lot of people used vb6 to create COM for use in Classic ASP.


    4) Visual Studio for ASP's intellisense is not very good. The only thing that application is good for is color coding and indenting. If you use Asp.net (1.x or 2.0) Visual Studio.net is very good. vs.net 2003 = 1.x (old), vs.net 2005 = 2.0 (current).


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page