checking username and password information against the db

Posted by Crp under C# on 9/14/2010 | Points: 10 | Views : 21814 | Status : [Member] | Replies : 7
What is the code for checking whether the username and password information entered in the textboxes are correct by checking the details in the DB? If it is invalid then it should prompt the user with the messagebox. Could anybody provide me the complete code in c#? I need to implement it in my windows application

Thanks

RAJAN C.R.P


Responses

Posted by: Peermohamedmydeen on: 9/14/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi Rajan,

In C# Winforms, we can achieve authentication in number of ways. It depends upon the user or application requirement and application architecture.

The basic way is sending UserName and Password as a parameter to the SP and get the authentication and subsequent authorization details back.

Once the authentication success allow the user to navigate the application by enabling menus. If authentication failed show the login form with 'Login Failed' Message.


Refer the below link. It will explain User Application authentication as well as Windows authentication which will authenticate with the user's active directory.

http://www.codeproject.com/KB/miscctrl/Application_Login.aspx







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

Posted by: T.saravanan on: 9/14/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Rajan,

http://www.daniweb.com/code/snippet217409.html

I hope this link useful to you.

Cheers :)

Thanks,
T.Saravanan

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

Posted by: Vuyiswamb on: 9/14/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
I saw this question asked all the time and i wrote an article that show a basic login System look at this

http://www.dotnetfunda.com/articles/article808-how-to-write-a-simple-login-page-in-aspnet-.aspx

Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: Syedshakeer on: 9/17/2010 [Member] Starter | Points: 25

Up
0
Down
Hi,
Use the below code to check UserName and Password

SqlCommand cmd=new SqlCommand("Select username,password from tablename where username='"+txtusername.Text+"' and password='"+textpassword.Text+"'");

SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
MessageBox("userName is already availables");

}
else
{
//write here insert command
}


Syed Shakeer Hussain

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

Posted by: Mandlaa on: 6/6/2013 [Member] Starter | Points: 25

Up
0
Down
I want to check password textbox data is correct or not??
Suppose i want to enter in-correct password display error message using database in asp.net,
I wnat to write that code in "Textboxcheckedchange event"

How can i write this one
plese help me

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

Posted by: Raj.Trivedi on: 6/6/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Mandlaa

The textbox changed event will not be suitable to achieve this logic..

It is better to perform the logic on button click event

The article of webmaster is the perfect one to execute the logic

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

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

Posted by: Mandlaa on: 6/10/2013 [Member] Starter | Points: 25

Up
0
Down
This is my actual code
How can i elemenate that type of error
string strCon = @System.Configuration.ConfigurationManager.ConnectionStrings["stgdbConnectionString"].ConnectionString;
string strSelect = "SELECT ClientId FROM CLIENT WHERE Email = @Email AND Password = @Password";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSelect;
SqlParameter email = new SqlParameter("@Email", SqlDbType.VarChar, 50);
email.Value = txtEmail.Text.Trim().ToString();
cmd.Parameters.Add(email);
SqlParameter password = new SqlParameter("@Password", SqlDbType.VarChar, 50);
password.Value = txtPwd.Text.Trim().ToString();
cmd.Parameters.Add(password);
con.Open();
clientid = cmd.ExecuteScalar().ToString();
con.Close();
if (clientid != null)
{
Session["Emailid"] = txtEmail.Text.ToString().Trim();
Session["ClientId"] = clientid;
Response.Redirect("Logout.aspx");
} else
lblMsg.Text = "Incorrect EmailId or Password";


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

Login to post response