C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




loginpage


Posted Date: 13 Aug 2008      Total Responses: 4

Posted By: Musturu Thippa Reddy       Member Level: Silver     Points: 1



hi friends , i am doing a Job postal project for my satisfaction i had a problem in login page plzzzz send the code for login page plzzzzzzzzzz(In ASP.NEt,c#)





Responses

Author: D.Jeya kumar(JK)    13 Aug 2008Member Level: DiamondRating:     Points: 2

Hi,


Please tell which Database you going to use and it is with database or without Database please post complete details of it.

Regards
JK



Author: Ramya    13 Aug 2008Member Level: GoldRating:     Points: 6

This is a sample. You should modify this for your requirement. Let’s say the name of the file is login.aspx.

Step 1: Create a design for the login page. For example, In the html type the following
<login.aspx>
<%@ Page language="c#" Codebehind=" login.aspx.cs" Inherits="login" %>

<html><body>
<form id="Form1" runat="server">

<p align=center>Login Form</P>
<p align=center><asp:Label id=”lblMsg” runat="server"></asp:Label></P>


<h4>Login</h4>
Username: <asp:TextBox id="txtUname" Runat="server" />
<asp:RequiredFieldValidator id="rfvUname" ControlToValidate="txtUname" ErrorMessage="Enter a valid user name" runat="server" />

<br/>
Password: <asp:TextBox id="txtPassword" Runat="server" TextMode="Password" />
<asp:RequiredFieldValidator ControlToValidate="txtPassword" ErrorMessage="Enter a valid password." id="rfvPassword" runat="server" />



<asp:Button id="btnSubmit" Runat="server" Text="Login" onClick="btnSubmit_Click" />
</form>
</body></html>

Step 2 : In the Code Behind, write the c# code for the login form
<login.aspx.cs>

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SQL;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace <namespace name>
{

public class login : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblMsg.Text = "Enter Username and Password to Login";
}
}

protected void btnSubmit_Click(Object obj, EventArgs e)
{
if (Page.IsValid)
{
// check for username & password in the database
SQLConnection conn = new SQLConnection("<connectionstring>");

// Get the row corresponding the given username and password
string strSQL = "Select * From <tablename> Where <userid column name>='" +
txtUname.Text + "' and <password column name> = '" +
txtPassword.Text + "'";

SQLDataSetCommand dsc = new SQLDataSetCommand(strSQL, conn);

// Fill the dataset
DataSet ds = new DataSet();
dsc.FillDataSet(ds, "Users");

// if there no entry then the user is invalid
if (ds.Tables["Users"].Rows.Count == 0)
{
lblMsg.Text = "Invalid User Name and Password. Try Again.";
}
else
{
lblMsg.Text = "Welcome, " + txtUname.Text +
"!!! You have successfully signed in.";
}
}
}

}
}



Author: Appukuttan    14 Aug 2008Member Level: DiamondRating:     Points: 6

Hello see this coding.This one with remember me option..

Design:

<table border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td class="logintext">
Login</td>
<td align="left">
:
</td>
<td align="left">
<asp:TextBox ID="txtLoginId" runat="server" CssClass="formobject"></asp:TextBox>
</td>
</tr>
<tr>
<td nowrap="nowrap" class="logintext">
Password</td>
<td align="left">
:
</td>
<td align="left">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" CssClass="formobject"></asp:TextBox>
</td>
</tr>
<tr>
<td nowrap="nowrap" class="logintext">
Password</td>
<td align="left">
:
</td>
<td align="left">
<asp:checkbox id="chkRememberMe" runat="server"/>
</td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
<td align="center">
<table width="154" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="77" align="center">
<asp:ImageButton ID="btnLogin" runat="server" ImageUrl="~/Images/login_button.png"
OnClick="btnLogin_Click" ValidationGroup="Login" alt="login" Width="77" Height="29" />
</td>
<td width="77" align="center">
<asp:ImageButton ID="btnCancel" OnClientClick="javascript:return Clear()" runat="server"
ImageUrl="~/Images/cancel_button.png" CausesValidation="False" alt="cancel" Width="77"
Height="29" />
</td>
</tr>
</table>
</td>
</tr>
</table>


Code Behind:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["myCookie"] != null)
{
HttpCookie cookie = Request.Cookies.Get("myCookie");
txtUserName.Text = cookie.Values["username"];
txtPassword.Text = cookie.Values["password"];
}
}
}

protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
objImpl = new WebImplIPhone();
bool IsAvailable = false;
HttpCookie myCookie = new HttpCookie("myCookie");
bool IsRemember = chkRememberMe.Checked;

IsAvailable = objImpl.CheckUserLogin(txtUserName.Text, txtPassword.Text);
if (IsAvailable)
{
DataTable dtUserName = objImpl.ReadUserIdbyUserName(txtUserName.Text);
if (dtUserName != null)
{
if (dtUserName.Rows.Count == 1)
{
Session["UserId"] = dtUserName.Rows[0].ItemArray[0].ToString();
}
}
if (IsRemember)
{
myCookie.Values.Add("username", txtUserName.Text);
myCookie.Values.Add("password", txtPassword.Text);
myCookie.Expires = DateTime.Now.AddDays(15);
}
else
{
myCookie.Values.Add("username", string.Empty);
myCookie.Values.Add("password", string.Empty);
myCookie.Expires = DateTime.Now.AddMinutes(5);
}
Response.Cookies.Add(myCookie);
//FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, chkRememberMe.Checked);
Response.Redirect("ApplicationList.aspx");
}
else
{
lblError.Text = "Invalid UserName or Password or else your Username blocked";
}
}
catch (Exception ex)
{
Response.Redirect("Home.aspx");
}
}



Author: InterviewsWorld    14 Aug 2008Member Level: SilverRating:     Points: 2

which database you are using?

Thanks,

<a href="http://www.interviewsworld.com" target="_blank">http://www.interviewsworld.com</a>



Post Reply
You must Sign In to post a response.
Next : Certification
Previous : DHTML Editor
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use