Answer the question
In order to leave comments, you need to log in
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.
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
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 questionAsk a Question
731 491 924 answers to any question