check login user

Posted by Pokuri31 under ASP.NET on 4/8/2009 | Views : 3622 | Status : [Member] | Replies : 5
Dear All,


I want one problem i have developed one application check whether the user is registered or not login name and pass word check these fields in databese.And i have developed three ways but not working. when ever we write the code using sessions also.



Thanking You,

Rana.




Responses

Posted by: Vuyiswamb on: 4/9/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Pokuri31

That is a Good Question, there are many ways to achieve this

First you need to have a StoredProcedure that will be returning 1 or 0 if the username and Password has been found and in your Application display the apropriate message if the user did not log in else send the user to a certain page. After the use clikcs the logout button or link or after the the user Closes your master page abondon the Session

Thank you For Posting at Dotnetfunda

Were hoping to hear from you

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: Vuyiswamb on: 4/9/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Here is the code that Explained Everything

First you have to Create a Storedprocure that counts the Records that match the username and password,

Create Procedure prclogin_check

(
@User_name varchar(20),
@U_Password varchar(23),
@Results int Output
)
IF EXISTS (Select cout(ID) from User_Table
where User_name =@User_name and U_Password = @U_Password)
Set @Results =1


And after you are done with this , you have to do the Following in your C# Code

using System.Data.SqlClient;


String strcon = "User id = sa;Password= topman;Server=myServer;Database=MyDB";
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandTimeout = 0;
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
cmdselect.CommandText = "prclogin_check";
cmdselect.Parameters.Add("@Results",SqlDbType.Int,4);
cmdselect.Parameters["@Results"].Direction = ParameterDirection.Output;
int Res;

try
{
con.Open();

cmdselect.ExecuteNonQuery();
Res = (int)cmdselect.Parameters["@Results"].Value;
con.Close();

}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}using System.Data.SqlClient;

String strcon = "User id = sa;Password= topman;Server=myServer;Database=MyDB";
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandTimeout = 0;
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
cmdselect.CommandText = "prclogin_check";
cmdselect.Parameters.Add("@Results",SqlDbType.Int,4);
cmdselect.Parameters["@Results"].Direction = ParameterDirection.Output;
int Res;

try
{
con.Open();

cmdselect.ExecuteNonQuery();
Res = (int)cmdselect.Parameters["@Results"].Value;
con.Close();

}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}


And in your Business logic or in your Form you can create a Function that will test if the Count of Records is greater than 0,if its less than that , then its invalid login

Hope this Helps

Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: Neeks on: 4/10/2009 [Member] Bronze

Up
0
Down
Instead of using Select * you can use Select count(*) it will give you faster result.

This will return 0 if you have provided wrong user name or and password combination.

select count(*) from user_master where UserName=@userName and password=@password


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

Posted by: Vuyiswamb on: 4/13/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
That is Correct

Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: Tridev_2005 on: 10/22/2009 [Member] Starter

Up
0
Down
Try this code
[code]if (strResult.Length > 0)
{
Label1.Text = "YOU ARE LOGGED IN!";
}

else
{
Label1.Text = "INCORRECT USER/PASS!"
}[/code]

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

Login to post response