E
E
EgorP132018-04-09 14:49:46
Database
EgorP13, 2018-04-09 14:49:46

How to output the data of an authorized user?

Hello, I made the authorization of the user in the program through the database by login and password. I wanted it to be after the login.
Here is the authorization code:

using (var con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\User\Desktop\база\Питание.mdf;Integrated Security=True;Connect Timeout=30"))
            {
                con.Open();
                using (var cmd = new SqlCommand("Select Count (1) From Регистрация where Логин[email protected] and Пароль[email protected]", con)) 
                {
                    cmd.Parameters.AddWithValue("login", textBox1.Text);
                    cmd.Parameters.AddWithValue("Pass", textBox2.Text);
                   
 
                    var accountsCount = (int)cmd.ExecuteScalar();
             
                    
                    if (accountsCount==1)
                    {
                        Form5 a = new Form5();
                        a.label1.Text = accountsCount.ToString();
                        a.Show();
                    }
                    else
                    {
                        MessageBox.Show("Неверные данные");
                    }
                 
                }
              
             
 
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Skorzhinsky, 2018-04-11
@AndyKorg

Che is a question in the wrong section, it's probably better to ask in C#.
And in the case, it seems like you have domain authorization "Integrated Security = True" there are cockroaches there.
For ms sql, you can read Security Functions (Transact-SQL) about the functions SUSER_SNAME, SUSER_NAME, etc.
Well, storing the password in a table is a bad idea.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question