Hello would like to know how I can create a user login in C # , I'm new in this forum, and programming has only incidentally 2 years
thanks for help
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.
Ryan AlfordPosted Dec 26, 2008, 10:50 AM
==================================================
private void btnLogin_Click(object sender, EventArgs e)
{
string connectionString = "whatever";
string sql = "SELECT COUNT(*) FROM Users WHERE Name = @Name AND Password = @Password";
using (SqlConnection cn = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(sql, cn))
{
cmd.Parameters.AddWithValue("@Name", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cn.Open();
int count = (int)cmd.ExecuteScalar();
if (count > 0)
MessageBox.Show("Login Successful", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Login Failed. Try Again.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
============================================================
Niradhip ChakrabortyPosted Dec 26, 2008, 10:06 AM
I have two textbox txtEmployeeID is for userName and txtPIN for password,onclick of submit button execute the following code. In my user table usr_vch_Name field is for userId and usr_vch_Password holds tha password
bool blnFound = false;
SqlConnection sqlCon = null;
Array arrOptions;
int intIndex = 0;
sqlCon = new SqlConnection(ConfigurationManager.AppSettings["con"].ToString());//fetching the connection string from web.config.
sqlCon.Open();
SqlCommand cmd = new SqlCommand("select * from Users where usr_int_Type=1 or usr_int_Type=3 ", sqlCon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr["usr_vch_Name"].ToString() == txtEmployeeID.Text)
{
if (dr["usr_vch_Password"].ToString() == txtPIN.Text)
{
blnFound = true;
// SUCCESSFULLY USER VALIDATED
}
}
}
if (!blnFound)
MessageBox.Show("Wrong login info is provided");
txtEmployeeID.Text = "";
txtPIN.Text = "";
dr.Close();
sqlCon.Close();
M K JangidPosted Dec 26, 2008, 8:29 AM