Javascript - login problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VLJones68
    New Member
    • May 2010
    • 3

    #1

    Javascript - login problem

    I have a website which contains the root directory, a MemberPages directory and a PublicPages directory.
    Default.aspx resides in the root directory and includes a javascript login. Upon clicking the Login button the user should be directed to a page within the MemberPages directory. I had this working, however added a new user last night and since then no logins are working. We are in progress on building a fully secure site with SQL Db however until that is complete I need to get this login script working again.
    When a user clicks on login the site tries to load the MemberPages page from the root directory. I am looking for some assistance as to how I get it to load the page from the MembersPages directory. I have had to shut part of the site down until this is fixed. I did have it working but in my stupidity I accidentally saved over the code and as I wrote in earlier in the year I have forgotten what it is I did to get it to work.

    Code from Default.aspx below. The login button should take the user to ~/MemberPages/BrkrDflt.aspx

    Any assistance would be GREATLY appreciated.

    Code:
    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
         Title="Home Page" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
      
        <!--
    
    CONTENT CONTAINER
    
    -->
        <div id="content-container-two-column" 
            <span style="font-family: Verdana">
            <!--
    
    CONTENT MAIN COLUMN
    
    -->
            </span>
            <div id="content-main-two-column">
                <h1 style="font-family: Verdana">
                    WELCOME</h1>
                    <div id="three-column-container" 
                    style="background-image: url('Images/Image1.png'); width: 696px;">
    
                    <div id="three-column-side1">
                        <img alt="" class="photo-border" src="Images/CrctBrd.png" 
                            style="height: 78px; width: 144px; font-family: Verdana;" />
                        <h2 style="font-family: Verdana">
                            Our Products</h2>
                        <p>
                            <span style="font-family: Verdana">
                            <span style="font-weight: normal">We provide speciality insurance on the</span>
                            <span style="font-weight: normal">following</span> <span style="font-weight: normal">products</span>:</p>
                        <p>
                            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Motor.aspx" Font-Bold="true">> Prestige Motor Vehicle</asp:HyperLink>
                        </p>
                        <p>
                            <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/BPK.aspx" 
                                Font-Bold="True">> Business Package</asp:HyperLink>
                        </p>
                        <p>
                            <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/ISR.aspx" 
                                Font-Bold="True">> Industrial Special Risks</asp:HyperLink>
                        </p>
                        <p>
                            <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="~/PLB.aspx" 
                                Font-Bold="True">> Broadform Liability</asp:HyperLink>
    
                        </div>
                    <div id="three-column-side2">
                        <img alt="" class="photo-border" src="Images/Calc.png" 
                            style="height: 78px; width: 144px" /></span>
                        <h2 style="font-family: Verdana">
                            Members Area</h2>
                        <table border="0" cellpadding="3" height="166" style="width: 201px">
    
                            <tr>
                                <td colspan="3" style="text-align: left">
                                    &nbsp;Please select your Username and enter your password to access.
                                </td>
                            </tr>
                            <tr>
                                <td class="style22" height="34">
                                    &nbsp;</td>
                                <td class="style21">
                                    <span class="style19">Username:</span></td>
                                <td class="style23">
                                    <div align="left">
                                        <span class="style19">
                                              <select name=memlist>
    <option value='x'>
    <option value='TPUA001|22896|KSNSLGLT'>TPUA001
    <option value='TPUA002|11718|CXKSLGLT'>TPUA002
    <option value='TPUA003|8073|DSPSLGLT'>TPUA003
    <option value='TPUA004|60588|DSSSEFLT'>TPUA004
    <option value='TPUA005|6615|CTPSLGLT'>TPUA005
    <option value='TPUA006|34560|CSNXENMT'>TPUA006
    <option value='TPUA007|38934|CWMWENMT'>TPUA007
    <option value='TPUA008|21924|ERKSLGLT'>TPUA008
    <option value='TPUA009|40257|CSLSLGLT'>TPUA009
            </select>
     </span>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td class="style22" height="35">
                                    &nbsp;</td>
                                <td class="style21" height="35">
                                    <span class="style19">Password:</span></td>
                                <td class="style23">
                                    <div align="left">
                                        <input maxlength="8" name="pass" size="10" type="password" />
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" class="style22" height="34">
                                    &nbsp;</td>
                                <td align="center" class="style21">
                                    &nbsp;</td>
                                <td align="center" class="style23">
                                    <div align="left">
                                        <input class="style15" name="button" onclick="check(this.form)" type="button"  
                                            value="Login"/>
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <span style="font-family: Verdana">
                        <asp:HyperLink ID="HyperLink6" runat="server" 
                            NavigateUrl="~/PublicPages/Apply.aspx" Font-Bold="True" 
                            >> Apply for a Log In</asp:HyperLink>
                        <br />
                        <br />
                        <asp:HyperLink ID="HyperLink5" runat="server" 
                            NavigateUrl="~/ForgotPassword.aspx" Font-Bold="True" 
                            Width="206px">> Forgotten your password?</asp:HyperLink>
                        <br />
                        <br />
                        </div>
                    <div id="three-column-middle">
                        <img alt="" class="photo-border" src="Images/Factory.png" 
                            style="height: 78px; width: 144px" /></span>
                        <h2 style="font-family: Verdana">
                            About Us</h2>
                        <p>
                            <span style="font-weight: normal; font-family: Verdana;">Trinity Pacific acts purely as a wholesale underwriting agency providing 
                            services on general insurance products. We do not deal with the direct public 
                            and only source business from licensed, general insurance brokers.</span><span 
                                style="font-family: Verdana"> </p>
                        <p>
                            <asp:HyperLink ID="HyperLink7" runat="server" 
                                NavigateUrl="~/About.aspx">> Read More</asp:HyperLink>
                        </p>
                        </div>
                </div>
            </div>
            <!--
    
    CONTENT SIDE COLUMN
    -->
    
            </span>
    
        </div>
        <script language="JavaScript">
    <!--        Begin
            var params = new Array(4);
            var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI";
            function check(form) {
                which = form.memlist.selectedIndex;
                choice = form.memlist.options[which].value + "|";
                if (choice == "x|") {
                    alert("Please Select Your User Name From The List");
                    return;
                }
                p = 0;
                for (i = 0; i < 3; i++) {
                    a = choice.indexOf("|", p);
                    params[i] = choice.substring(a, p);
                    p = a + 1;
                }
                h1 = makehash(form.pass.value, 3);
                h2 = makehash(form.pass.value, 10) + " ";
                if (h1 != params[1]) {
                    alert("Incorrect Password!"); return;
                };
                var page = "";
                for (var i = 0; i < 8; i++) {
                    letter = params[2].substring(i, i + 1)
                    ul = letter.toUpperCase();
                    a = alpha.indexOf(ul, 0);
                    a -= (h2.substring(i, i + 1) * 1);
                    if (a < 0) a += 26;
                    page += alpha.substring(a, a + 1);
                };
                top.location = page.toLowerCase() + ".aspx";
            }
            function makehash(pw, mult) {
                pass = pw.toUpperCase();
                hash = 0;
                for (i = 0; i < 8; i++) {
                    letter = pass.substring(i, i + 1);
                    c = alpha.indexOf(letter, 0) + 1;
                    hash = hash * mult + c;
                }
                return (hash);
            }
    // End -->
              </script>
    
    </asp:Content>
    Last edited by Dormilich; Nov 23 '10, 08:12 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    You have no form on your page but you reference a form several times in your code and try to pass in a form as a parameter to one of your functions. Likely you are getting a javascript error of "form is null" because there is no form.

    Storing the usernames and passwords the way you are doing is really bad practice and is a huge security risk. I would skip fixing this and move straight into using a database if at all possible.

    Always backup your files before making changes.

    Comment

    • VLJones68
      New Member
      • May 2010
      • 3

      #3
      Thanks. I am aware this is not the best way to do it, unfortunately I am cannot commence building the database version until the contract is signed (prob in the new year) so I really need to get this working again in the interim.

      I am not getting any form errors just that upon clicking the login button that it tries to navigate to the page in the root directory instead of the memberpages directory.

      Thanks again.

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Line 169 - 178 you build a string and then send the user to that page. I would try using an alert around your page string to make sure it is where you want to send the user.

        Comment

        Working...