Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,670 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,033 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Login Form

 
Reply to this topicStart new topic

Login Form, Create Login From Using Classes

RamaDeviDodda
post 3 Jul, 2008 - 12:30 AM
Post #1


New D.I.C Head

*
Joined: 3 Jul, 2008
Posts: 1

I want the login form with the oops concepts in C# .Net.
I know this is a basic question, but I am not familiar with oops concepts.
I want the code to be writtten in classes and it is to be inherited in code
Can uplease help me to get the code
I tried the login form as below

Login.aspx

CODE

<table align="center" cellpadding="10">
       <tr>
           <td colspan="2" align="center">
              <asp:Label runat="server" ID= "lbl_login" Text="Login Form" Font-Bold="True"></asp:Label>
           </td>
       </tr>
    
       <tr>
           <td>
               <asp:Label runat="server" ID= "lbl_username" Text="User Name" ></asp:Label>
           </td>
          
           <td>
               <asp:TextBox runat="server" ID="txt_username"  ></asp:TextBox>
           </td>
       </tr>
      
       <tr>
            <td>
               <asp:Label runat="server" ID= "lbl_password" Text="Password" ></asp:Label>
            </td>
            
            <td>
               <asp:TextBox runat="server" ID="txt_password" TextMode="Password"  ></asp:TextBox>
            </td>
       </tr>
      
       <tr>
            <td align="center">
                <asp:Button runat="server" ID="btn_login" Text="Login" OnClick="btn_login_Click" />
            </td>
            
            <td align="center">
                <asp:Button runat="server" ID="btn_cancel" Text="Cancel" OnClick="btn_cancel_Click" />
            </td>
       </tr>
        <tr>
            <td align="center" colspan="2">
                <asp:Label ID="lbl_err" runat="server" Text="UserName and Password doesn't match" Font-Italic="True" ForeColor="DeepSkyBlue" Visible="False"></asp:Label></td>
        </tr>
      
    </table>


Login.aspx.cs

CODE

protected void btn_login_Click(object sender, EventArgs e)
    {
      
        SqlConnection cn = new SqlConnection("server=192.168.0.1;user id=practice1;password=teamwork;database=practice");
        cn.Open();
        SqlCommand cmd = new SqlCommand("select * from RamaLogin where UserName ='" + txt_username.Text + "' and Password='" + txt_password.Text + "' ", cn);
        SqlDataReader dr;
        dr = cmd.ExecuteReader();

        if (dr.HasRows == true)
        {
            dr.Close();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataRow drt = ds.Tables[0].Rows[0];
            string user = drt[0].ToString();
            string password  = drt[1].ToString();

            if(user == txt_username.Text && password == txt_password.Text)
                  Response.Redirect("welcome.aspx?Name=" + this.txt_username.Text);
             else
                  lbl_err.Visible = true;
            
        }

        else
        {
            lbl_err.Visible = true;
        }
        cn.Close();

    }


Welcome.aspx

CODE

<table align="center" >
       <tr>
           <td>
               <asp:Label runat="server" ID="lbl_welcome" Font-Bold="True" Font-Italic="True" Font-Size="16pt"></asp:Label>
           </td>
       </tr>
    </table>


Welcome.aspx.cs

** Edit ** code.gif
User is offlineProfile CardPM

Go to the top of the page


no2pencil
post 3 Jul, 2008 - 01:05 AM
Post #2


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 4,840



Thanked 27 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


Just a bit of advice, if you want people to help you, make the text easier to read... not harder.
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/29/08 11:08PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month