simple Login form which is dynamic

Posted by 0194ca071007 under Regular Expressions on 3/31/2011 | Points: 10 | Views : 9861 | Status : [Member] | Replies : 3
hello there !
As i ma begineer and want to learn dot net .I need a Login page in asp dotnet which is dynamic user enter his name and password and Logged on to the next Page plz send as soon as possible waiting for ur reply
thnkz




Responses

Posted by: SheoNarayan on: 3/31/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
You can read this article http://www.dotnetfunda.com/articles/article114.aspx that focus on this topic.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

0194ca071007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 4/1/2011 [Member] Bronze | Points: 25

Up
0
Down
You can create a login page by using the ASP.NET Login control.
Check this link for more about login control: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.aspx
To create a login page

1.

Create an ASP.NET Web application that uses ASP.NET membership. For more information and examples, see Walkthrough: Creating a Web Site with Membership and User Login. For information about how to configure membership, see Configuring an ASP.NET Application to Use Membership.
2.

Create an ASP.NET Web page named Login.aspx in your application.

By default, ASP.NET forms authentication is configured to use a page named Login.aspx. You can change the default login page name in the Web.config file for your application using the LoginUrl property.
3.

Add a Login control to the page from the tool box.
4.

Set the control's DestinationPageURL property to the name of the page that the user will be redirected to after they log in. For example, you can set the DestinationPageUrl property to DestinationPageUrl="~/Membership/MembersHome.aspx", a members only page. If you do not specify a value for the DestinationPageURL property, the user will be redirected to the original page the user requested after successfully logging in.

The following example shows the markup for a Login control:
[code]

<asp:Login
ID="Login1"
runat="server"
DestinationPageUrl="~/MembersHome.aspx">
</asp:Login>
[code]
More sample code show here
[code]using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
// <summmary>
// What has been added for Login Page
// for this application to function
// </summary>
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;

namespace NorthCSharp
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.RequiredFieldValidator rvUserValidator;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator;
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.ValidationSummary Validationsummary1;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblMessage2;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void cmdSubmit_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()))
{
FormsAuthentication.RedirectFromLoginPage (txtUserName.Text, false);
}
else
{
lblMessage.Text = "Invalid Login, please try again!";
}
}

}
private bool DBConnection(string txtUser, string txtPass)
{
SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCmd = new SqlCommand("sp_ValidateUser", myConn);
myCmd.CommandType = CommandType.StoredProcedure;

SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter returnParam;

objParam1 = myCmd.Parameters.Add ("@UserName", SqlDbType.VarChar);
objParam2 = myCmd.Parameters.Add ("@Password", SqlDbType.VarChar);
returnParam = myCmd.Parameters.Add ("@Num_of_User", SqlDbType.Int);

objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
returnParam.Direction = ParameterDirection.ReturnValue;

objParam1.Value = txtUser;
objParam2.Value = txtPass;

try
{
if (myConn.State.Equals(ConnectionState.Closed))
{
myConn.Open();
myCmd.ExecuteNonQuery();
}
if ((int)returnParam.Value < 1)
{
lblMessage.Text = "Invalid Login!";
return false;
}
else
{
myConn.Close();
return true;
}
}
catch (Exception ex)
{
lblMessage2.Text = ex + "Error Connecting to the database";
return false;
}

}
}
}[/code]

LP MER

0194ca071007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 4/3/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Check this link

http://codeasp.net/blogs/Vijjendra/microsoft-net/149/create-login-page-in-asp-net

Thanks
Karthik
www.f5Debug.net

0194ca071007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response