Forum guidelines
How to create an user login in C# with Forms
Posted By Rodolfo on 26 Dec 2008
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

Re: How to create an user login in C# with Forms
Posted By M K Jangid on 26 Dec 2008  
Hello What are u want to know? About Login Page UI or Connectivity of Login control with Database? you can drag and drop Login control from toolbox!!!!!
Regards, M K Jangid
Re: How to create an user login in C# with Forms
Posted By Niradhip Chakraborty on 26 Dec 2008  

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.

                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 = "";

Niradhip(James Hetfield)
Please remember to click “Do you like this answer” on the post that helps you.
Re: How to create an user login in C# with Forms
Posted By Ryan Alford on 26 Dec 2008  
or, you could use this....

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);


            int count = (int)cmd.ExecuteScalar();

            if (count > 0)
                MessageBox.Show("Login Successful", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MessageBox.Show("Login Failed.  Try Again.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);




Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.