hello there ...
this is praveen i want to know that how i can create a secure login page using asp.net and c# coding without using the visual studio login control..
help me please..
thank you.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jun 27, 2012, 11:37 PM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Login_and_signup._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Login_and_signup
{
public partial class _Default : System.Web.UI.Page
{
protected void btnSignin_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtUserName.Text) && !string.IsNullOrEmpty(txtPassword.Text))
{
//SqlConnection sqlConnection = new SqlConnection();
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(connStr);
//sqlConnection.ConnectionString = @"Data Source=SS438\SQLEXPRESS;Initial Catalog=Examples;Integrated Security=true;";
sqlConnection.Open();
string sqlQuery = "SELECT * FROM Users WHERE UserName=@UserName AND Password=@Password";
SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection);
sqlCommand.CommandType = CommandType.Text;
sqlCommand.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtUserName.Text.Trim();
sqlCommand.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtPassword.Text.Trim();
SqlDataReader sreader = sqlCommand.ExecuteReader();
string _userName = string.Empty;
string _password = string.Empty;
while (sreader.Read())
{
_userName = sreader[3].ToString();
_password = sreader[4].ToString();
}
sqlConnection.Close();
if (txtUserName.Text.Trim() == _userName && txtPassword.Text.Trim() == _password)
{
Response.Redirect("welcome.aspx");
}
else
{
lblMessage.Text = "User name/password wrong! Try again!!";
}
}
else
{
}
}
protected void lbtnsignup_Click(object sender, EventArgs e)
{
Response.Redirect("Registration.aspx");
}
protected void btnExit_Click(object sender, EventArgs e)
{
}
}
}
Thanks
If this post helps you mark it as answer
Satyapriya NayakPosted Jun 27, 2012, 11:29 PM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Login_Page_Using_Stored_Procedure._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Login_Page_Using_Stored_Procedure
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlParameter UserName, Password;
protected void btn_login_Click(object sender, EventArgs e)
{
UserName = new SqlParameter();
Password = new SqlParameter();
SqlConnection con = new SqlConnection(strConnString);
com=new SqlCommand();
com.Connection = con;
con.Open();
Session["UserName"] = TextBox_user_name.Text;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "login_pro";
UserName.SqlDbType = SqlDbType.VarChar;
UserName.Size = 50;
UserName.ParameterName = "@UserName";
UserName.Value = TextBox_user_name.Text.ToString();
UserName.Direction = ParameterDirection.Input;
Password.SqlDbType = SqlDbType.VarChar;
Password.Size = 50;
Password.ParameterName = "@Password";
Password.Value = TextBox_password.Text.ToString();
Password.Direction = ParameterDirection.Input;
com.Parameters.Add(UserName);
com.Parameters.Add(Password);
int status;
status = Convert.ToInt16(com.ExecuteScalar());
if (status == 1)
{
Response.Redirect("Welcome.aspx");
}
else
{
lblmessage.Text = "Invalid UserName and Password...";
}
con.Close();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="Login_Page_Using_Stored_Procedure.Welcome" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Login_Page_Using_Stored_Procedure
{
public partial class Welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lb1.Text = "WELLCOME :: " + Session["UserName"];
}
}
}
Thanks
If this post helps you mark it as answer
Satyapriya NayakPosted Jun 27, 2012, 11:23 PM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="login_using_parameter._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace login_using_parameter
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;
protected void btn_login_Click(object sender, EventArgs e)
{
object obj = null;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select count(*) from login where UserName=@UserName and Password =@Password";
com = new SqlCommand(str, con);
com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@UserName", TextBox_user_name.Text);
com.Parameters.AddWithValue("@Password", TextBox_password.Text);
obj = com.ExecuteScalar();
if ((int)(obj) != 0)
{
lb1.Text = "WELLCOME :: " + TextBox_user_name.Text;
}
else
{
lb1.Text = "invalid user name and password";
}
con.Close();
}
}
}
Thanks
If this post helps you mark it as answer