Create Login Session

Posted by Kjksdm under ASP.NET on 4/8/2012 | Points: 10 | Views : 10286 | Status : [Member] | Replies : 5
I am new to .net please help me.
I need to create session based on the user login form. need to store loginID into session

store procedure
--------------------------------
CREATE PROCEDURE [dbo].[usp_USER_Login]
@UserID varchar(100),
@Password varchar(100)
AS
BEGIN
SELECT LoginID FROM tbl_registration WHERE UserID = @UserID AND [Password] = @Password
END
GO

c# coding
----------------------------------
protected void btnLogin_Click(object sender, EventArgs e)
{
RegistrationDO regLogin = new RegistrationDO();

string userID = txtUserID.Text;
string password = txtPassword.Text;

if (!string.IsNullOrEmpty(userID) && !string.IsNullOrEmpty(password))
{
RegistrationDO loginDO = new RegistrationDO();
loginDO.UserID = userID;
loginDO.Password = password;

bool result = RegistrationDAL.CheckUserLogin(loginDO);
if (result)
Response.Redirect("~/success.aspx");
else
lblMessage.Text = "Failed";
}
}

DataAccess Code
-----------------------------------------------
public static bool CheckUserLogin(RegistrationDO regDO)
{
SqlConnection connec = new SqlConnection(ConfigurationManager.AppSettings["SQL"]);
SqlCommand cmd = null;
DataTable dt = null;
bool RetVal = false;
try
{
conn.Open();
cmd = new SqlCommand("usp_USER_Login", connec);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@UserID",regDO.UserID));
cmd.Parameters.Add(new SqlParameter("@Password", regDO.Password));

int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
RetVal = true;
}
catch(Exception ex)
{
RetVal = false;
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}

return RetVal;
}




Responses

Posted by: Taanu51 on: 4/8/2012 [Member] Starter | Points: 25

Up
0
Down
Hi, We can create login page and logout page using sessions

Click on the following links it may helps you

http://www.developerscode.com/2011/02/how-to-create-login-page-in-aspnet-with.html

http://www.developerscode.com/2011/02/how-to-create-logout-page-using.html

http://www.developerscode.com/2012/03/journey-from-login-page-to-logout-page.html

let me know..!

Tanisha Sayyad
.Net and Android Developer
INDIA(Andhra Pradesh)

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

Posted by: Hariinakoti on: 4/8/2012 [Member] Starter | Points: 25

Up
0
Down
this link is useful to u...
http://www.dotnetfunda.com/articles/article808-how-to-write-a-simple-login-page-in-aspnet.aspx

Thanks & Regards
Hari

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

Posted by: Rajni.Shekhar on: 4/9/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

check it.

protected void btnLogin_Click(object sender, EventArgs e) 

{
RegistrationDO regLogin = new RegistrationDO();

string userID = txtUserID.Text;
string password = txtPassword.Text;

if (!string.IsNullOrEmpty(userID) && !string.IsNullOrEmpty(password))
{
RegistrationDO loginDO = new RegistrationDO();
loginDO.UserID = userID;
loginDO.Password = password;

bool result = RegistrationDAL.CheckUserLogin(loginDO);
if (result)
{
Session["UserID"]=userID;//session os userid will store the value of user id through out the application. you can access it at any page. Response.Redirect("~/success.aspx");
}
else
lblMessage.Text = "Failed";
}
}


Thanks,
Rajni Shekhar

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

Posted by: Patel28rajendra on: 4/9/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

visit this link

http://www.dotnetuncle.com/Aspnet/85_session.aspx

R D Patel

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

Posted by: perfectchourasia-9163 on: 6/8/2012 [Member] Starter | Points: 25

Up
0
Down
Before redirecting to another page create session

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

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

Login to post response