I use userlogin and password to login . After successfully login i want to show welcome username instead of userlogin. Do you guys have any idea of how to do that ?
This is my stored procedure .
USE [Test]
GO
/****** Object: StoredProcedure [VRM].[Login] Script Date: 06/25/2012 17:41:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [VRM].[Login]
(
@Userlogin VarChar(50),
@UPassword varChar(50),
@OutRes int OUTPUT
)
AS
set @OutRes = (SELECT count(*) FROM Common.tbl_employee
WHERE [userlogin] = @Userlogin And [password] = @UPassword)
if(@OutRes = 1)
begin
set @OutRes = 1 --Login is Correct
end
else
begin
set @OutRes = 0 --Bad login
end
This is my ValidateLogin method and Login Button
public int Validate_Login(String UserLogin, String Password)
{
SqlConnection con = new SqlConnection(@"User id=sa;Password=passw0rd;Server=L33524;Database=Test");
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.CommandText = "VRM.Login";
cmdselect.Parameters.Add("@Userlogin", SqlDbType.VarChar, 50).Value = UserLogin;
cmdselect.Parameters.Add("@UPassword", SqlDbType.VarChar, 50).Value = Password;
cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4);
cmdselect.Parameters["@OutRes"].Direction = ParameterDirection.Output;
cmdselect.Connection = con;
int Results = 0;
Hi keep your login related button text fields and labels on separate form and in case login is successfull hide that form by setting its visible property to false and show main window if login is not successful then show same form again with error messages
(may be more than one).
singaporestr...
Member
6 Points
33 Posts
After login how to show username
Jun 25, 2012 09:48 AM|LINK
I use userlogin and password to login . After successfully login i want to show welcome username instead of userlogin. Do you guys have any idea of how to do that ?
This is my stored procedure .
USE [Test]
GO
/****** Object: StoredProcedure [VRM].[Login] Script Date: 06/25/2012 17:41:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [VRM].[Login]
(
@Userlogin VarChar(50),
@UPassword varChar(50),
@OutRes int OUTPUT
)
AS
set @OutRes = (SELECT count(*) FROM Common.tbl_employee
WHERE [userlogin] = @Userlogin And [password] = @UPassword)
if(@OutRes = 1)
begin
set @OutRes = 1 --Login is Correct
end
else
begin
set @OutRes = 0 --Bad login
end
This is my ValidateLogin method and Login Button
public int Validate_Login(String UserLogin, String Password)
{
SqlConnection con = new SqlConnection(@"User id=sa;Password=passw0rd;Server=L33524;Database=Test");
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.CommandText = "VRM.Login";
cmdselect.Parameters.Add("@Userlogin", SqlDbType.VarChar, 50).Value = UserLogin;
cmdselect.Parameters.Add("@UPassword", SqlDbType.VarChar, 50).Value = Password;
cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4);
cmdselect.Parameters["@OutRes"].Direction = ParameterDirection.Output;
cmdselect.Connection = con;
int Results = 0;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
// String UserName = Convert.ToString(cmdselect.Parameters["@username"].Value); // just added
Results = (int)cmdselect.Parameters["@OutRes"].Value;
}
catch (SqlException ex)
{
// lblMessage.Text = ex.Message;
}
finally
{
cmdselect.Dispose();
if (con != null)
{
con.Close();
}
}
return Results;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
int Results = 0;
if (txtUsername.Text != string.Empty && txtPassword.Text != string.Empty || txtUsername.Text == string.Empty || txtPassword.Text == string.Empty)
{
Results = Validate_Login(txtUsername.Text.Trim(), txtPassword.Text.Trim());
bool roles = Roles.LoginRoles(txtUsername.Text, txtPassword.Text);
// if roles is activated && result is found , login success
if (roles == false && Results == 1)
{
// lblMessage.Text = "Welcome: " + txtUsername.Text;
Session["name"] = txtUsername.Text;
Server.Transfer("MainDashboard.aspx");
}
else if (roles == true)
{
lblMessage.Text = "User is deactivated, unable to log in !";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
else
{
lblMessage.Text = "Invalid Login";
lblMessage.ForeColor = System.Drawing.Color.Red;
//Dont Give too much information this might tell a hacker what is wrong in the login
}
}
else
{
Session["name"] = txtUsername.Text;
Server.Transfer("MainDashboard.aspx");
}
}
marinac
Member
154 Points
146 Posts
Re: After login how to show username
Jun 25, 2012 09:54 AM|LINK
if (Request.IsAuthenticated) { Label1.Text = Context.User.Identity.Name; }PINET
Member
626 Points
150 Posts
Re: After login how to show username
Jun 25, 2012 09:55 AM|LINK
Hi keep your login related button text fields and labels on separate form and in case login is successfull hide that form by setting its visible property to false and show main window if login is not successful then show same form again with error messages (may be more than one).
singaporestr...
Member
6 Points
33 Posts
Re: After login how to show username
Jun 25, 2012 10:00 AM|LINK
Try the above code but after login successfully , it show me the computer name. Do i have to changed my stored procedure ?
Cause my store procedure did not get the username out .
marinac
Member
154 Points
146 Posts
Re: After login how to show username
Jun 25, 2012 10:19 AM|LINK
In login page put username in session and after only read session...