Welcome to Dream.In.Code
Become an Expert!

Join 150,105 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,873 people online right now. Registration is fast and FREE... Join Now!




Login Form

 
Reply to this topicStart new topic

Login Form, Create Login From Using Classes

RamaDeviDodda
2 Jul, 2008 - 11:30 PM
Post #1

New D.I.C Head
*

Joined: 2 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
+Quote Post

no2pencil
RE: Login Form
3 Jul, 2008 - 12:05 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,163



Thanked: 78 times
Dream Kudos: 2425
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
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:50AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month