V
V
Virtual Programmer2016-12-30 13:03:42
MySQL
Virtual Programmer, 2016-12-30 13:03:42

How to make authorization in the program through the mysql database?

The task is

  1. In the authorization form, you need to connect to the database on the local server (you can also on the site)
  2. When you click on the Login button, if the data matches, then go to another form, if they do not match, show Label_Erorr.Text = "Error Login Pass";
  3. When you click on the Register button, a form opens, everything is entered there and a new client is added to the database
private void RegisterBtn_Click(object sender, EventArgs e)
        {
            this.Hide(); // Скрыть 1 форму 
            Register reg = new Register(); // Создать новую 2 форму
            reg.ShowDialog(); // Отобразить форму
            this.Close(); // Закрыть 1 форму
        }
 private void LoginBtn_Click(object sender, EventArgs e)
        {
            string CommandText = "SELECT * FROM users WHERE Username= " + LoginBox.Text + " AND password = " + PassBox.Text + " LIMIT 1";
            string Connect = "Database=kbecker;Data Source=localhost;User Id=root;Password=";
            SqlConnection myConnection = new SqlConnection(Connect);
            SqlCommand myCommand = new SqlCommand(CommandText, myConnection);
            myConnection.Open();
            /*
            Что тут писать если верно, или неверно
            */
            myConnection.Close();
            if (LoginBox.Text == "Anonymous" && PassBox.Text == "kgp193mdl250")
            {
                this.Hide();
                Main fm = new Main();
                fm.ShowDialog();
                this.Close();
            }
        }
private void RememberCheck_CheckedChanged(object sender, EventArgs e)
        {
            if (RememberCheck.Checked == true)
            {
                LoginBox.Text = "Anonymous";
                PassBox.Text = "kgp193mdl250";
            }
            else
            {
                LoginBox.Clear();
                PassBox.Clear();
            }
        }

17307178c0b24d94aaa3078f94e9e6bc.png54ec2cf426db4cf1b399883eed46a7ea.png0061ee6bd5e14007bf585e7d7d7d453e.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2016-12-31
@devspec

Are you trying to do all this in WinForms? Wouldn't it be better to think about ASP .NET?
PS Use ORM instead of such strange sheets of code. For example, Dapper.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question