Login problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MissElegant
    New Member
    • May 2008
    • 17

    #1

    Login problem

    Hi my Friends,

    I dont know what is the problem in my code, Could somebody help me please??

    ===

    this is the page:
    ===

    Code:
     <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <div align="left" style="text-align: center">
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
            <table style="z-index: 102; left: 290px; position: absolute; top: 50px">
                <tr>
                    <td align="center" style="width: 438px; height: 14px" valign="middle">
                        &nbsp;</td>
                </tr>
                <tr>
                    <td align="left" style="width: 438px" valign="middle">
                        <table align="center">
                            <tr>
                                <td style="font-weight: bold; width: 265px">
                                    &nbsp;Please login to access the Website<br />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td align="left" style="width: 438px" valign="middle">
                        <table align="center">
                            <tr>
                                <td style="width: 77px; height: 26px">
                                    <asp:Label ID="Label1" runat="server" Text="User Name:"></asp:Label></td>
                                <td style="width: 191px; height: 26px">
                                    <asp:TextBox ID="userName" runat="server"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 77px">
                                    <asp:Label ID="Label2" runat="server" Text="Password: "></asp:Label></td>
                                <td style="width: 191px">
                                    <asp:TextBox ID="passWord" runat="server" TextMode="Password"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 77px">
                                    </td>
                                <td style="width: 191px">
                                    </td>
                            </tr>
                            <tr>
                                <td style="width: 77px">
                                </td>
                                <td style="width: 191px">
                                    <asp:Button ID="submit" runat="server" OnClick="submit_Click" Text="Submit" /></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <br />
            <br />
            &nbsp; &nbsp;<br />
            <br />
            <br />
            <br />
            &nbsp; &nbsp;<br />
            &nbsp; &nbsp;&nbsp;<br />
            <br />
            <br />
            <br />
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp;<br />
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            <br />
        </div>
    </asp:Content>
    =============== ==========
    =============== =========


    this is the C# code for this page
    =========
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    
    public partial class _Default : System.Web.UI.Page
    {
        public void checkUser(String username, String password)
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionToEL"].ConnectionString);
                cmd.CommandText = @"select * from " ;
                cmd.Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    string name = reader[0].ToString();
                    string pass = reader[1].ToString();
                    if ((name.Equals(username)) && (pass.Equals(password)))
                    {
                        Response.Redirect( "StudentHome.aspx");
    
                    }
                }
                reader.Close();
                cmd.Connection.Close();
            }
    
            Response.Redirect("Default.aspx");
    
    
    
        }
        protected void submit_Click(object sender, EventArgs e)
        {
            String n = this.userName.Text;
            String p = this.passWord.Text;
           
            checkUser(n, p);
    
        }
    
    }
    =============== =========

    the problem is in the

    "Line 22: SqlDataReader reader = cmd.ExecuteRead er();"

    ???
    Every thing else is OK regarding the Database. I created a table in the database with Mouza as username & 123457 as password.

    Could somebody help me here... please...
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Is there an error-message?

    Steven

    Comment

    • MissElegant
      New Member
      • May 2008
      • 17

      #3
      Originally posted by MrMancunian
      Is there an error-message?

      Steven

      when I run the application , it says to me:


      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

      Exception Details: System.Data.Sql Client.SqlExcep tion: Incorrect syntax near 'from'.

      Source Error:


      Line 20: cmd.CommandText = @"select * from ";
      Line 21: cmd.Connection. Open();
      Line 22: SqlDataReader reader = cmd.ExecuteRead er();
      Line 23: while (reader.Read())
      Line 24: {



      Source File: d:\Documents and Settings\myPC\M y Documents\Visua l Studio 2005\WebSites\E-CV\Default.aspx .cs Line: 22


      --------------
      when I debug it..
      it says in the locals
      $exception {"Incorrect syntax near 'from'."} System.Exceptio n {System.Data.Sq lClient.SqlExce ption}

      Comment

      • MissElegant
        New Member
        • May 2008
        • 17

        #4
        Thanks I solved the problem, I feel so stupid.
        I did not specify the table the IAm getting the info from..

        I have another question?
        If iam logged in already, and I press back button. It should not ask me to write the username and the password again??

        how can I do that?
        could u help me?

        Comment

        • MrMancunian
          Recognized Expert Contributor
          • Jul 2008
          • 569

          #5
          Try using a session and check wheter or not the session is active.

          Steven

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            But you will have to get around the browser cache. When you hit the back button, you aren't downloading the page again, it is showing you what it has stored in memory. I have read that this code will prevent that, but I haven't actually tried it myself.
            Code:
            Protected void Page_Init(object Sender, EventArgs e)
            {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
            }
            And then you will have to check in the Page_Load method if you are already logged in. I suggest that you set a Session variable true or false, and check that value.

            Comment

            • MissElegant
              New Member
              • May 2008
              • 17

              #7
              Originally posted by insertAlias
              But you will have to get around the browser cache. When you hit the back button, you aren't downloading the page again, it is showing you what it has stored in memory. I have read that this code will prevent that, but I haven't actually tried it myself.
              Code:
              Protected void Page_Init(object Sender, EventArgs e)
              {
              Response.Cache.SetCacheability(HttpCacheability.NoCache);
              Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
              }
              And then you will have to check in the Page_Load method if you are already logged in. I suggest that you set a Session variable true or false, and check that value.

              I tried it, but it doesn't work
              I searching also!!
              Iam confused

              Comment

              Working...