Answer the question
In order to leave comments, you need to log in
Authorization c# mysql., separation of users!?
C# WinForms Mysql, made authorization via login/password (pre-written in the database, without registration). How to make it so that, for example, the user who entered the login / password Admin / Admin opened one window, and the user who entered user / user opened another window.
I don't really understand how this can be done...
Answer the question
In order to leave comments, you need to log in
Imagine that you have a user
table
. This table has the following columns :
string connStr = "server=localhost; port=3306; username=root; password= root; database=bd;";
string sql = "SELECT * FROM `user` WHERE `Name` = @un and `Password`= @up";
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
DataTable table = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand command = new MySqlCommand(sql, conn);
command.Parameters.Add("@un", MySqlDbType.VarChar, 25);
command.Parameters.Add("@up", MySqlDbType.VarChar, 25);
command.Parameters["@un"].Value = TextBox1.Text;
command.Parameters["@up"].Value = TextBox2.Text
adapter.SelectCommand = command;
adapter.Fill(table);
if (table.Rows.Count > 0)
{
userRole(); // метод, который будет открывать разные формы в зависимости от пользователя
}
conn.Close();
string UserName = TextBox1.Text;;
string connStr = "server=localhost; port=3306; username=root; password= root; database=bd;";
string sql = "SELECT User_Role FROM `user` WHERE `Name` = @un";
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
MySqlParameter nameParam = new MySqlParameter("@un", UserName);
MySqlCommand command = new MySqlCommand(sql, conn);
command.Parameters.Add(nameParam);
string Form_Role = command.ExecuteScalar().ToString();
Switch(Form_Role)
{
case "Администратор": Form.ActiveForm.Close(); Form1 f1 = new Form1(); f1.Show(); break;
default: Form.ActiveForm.Close(); Form2 f2 = new Form2(); f2.Show();
}
conn.Close();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question