A
A
Alek52018-10-24 20:57:47
C++ / C#
Alek5, 2018-10-24 20:57:47

How to do authorization and registration in C#?

How to make authorization using Windows Form to MSQL. Login and password must be entered in the form and stored in the database.
5bd0b274a0dcf572860177.jpeg
Example:

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
 
        private DataTable Load_data()
        {
            DataTable dt = new DataTable();
            MySqlConnectionStringBuilder mysqlCSB;
            mysqlCSB = new MySqlConnectionStringBuilder();
            mysqlCSB.Server = "127.0.0.1";
            //адрес сервера
            mysqlCSB.Database = "mydb";
            //наименование базы данных
            mysqlCSB.UserID = "root";
            //имя пользователя
            mysqlCSB.Password = "";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Floydreme, 2018-10-24
@Alek5

Here is an example in WPF. I hope the train of thought is clear

MySqlConnection con = new MySqlConnection(@"host=localhost; port = your.PORT;User id = root; password = 'your.PASS'; SslMode = true; Database ='your.DATABASE'");
public int I;

private void Login_Click(object sender, RoutedEventArgs e)
{
    I = 0;
    con.Open();
    MySqlCommand cmd = con.CreateCommand();
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "select * from user where username = '"+username.Text+"'and pass= '"+PasswordBox.Password+"'";
    DataTable dt = new DataTable();
    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
    da.Fill(dt);
    I = Convert.ToInt32(dt.Rows.Count.ToString());
    if (I == 0)
    {
        //Выдать ошибку
     }
    else
     {
           this.Hide();
           MainPage mp = new MainPage();
           mp.Show();
      }
           con.Close();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question