Ejemplo n.º 1
0
        private void Hello_MouseEnter(object sender, MouseEventArgs e)
        {
            while (k < 1)
            {
                k = 1;
                string           S***n   = Name.Text;
                DB               db      = new DB();
                DataTable        table   = new DataTable();
                MySqlDataAdapter adapter = new MySqlDataAdapter();
                db.openConnection();



                MySqlCommand command = new MySqlCommand("SELECT `name`,`secondname`  FROM `users` WHERE  `login`=@lU", db.getConnection());
                command.Parameters.Add("@lU", MySqlDbType.VarChar).Value = S***n;

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var fname = reader["name"].ToString();
                        var sname = reader["secondname"].ToString();
                        Hello_User.Text = fname;
                        Name.Text       = sname;
                    }
                }

                db.closeConnection();


                Scroll_Menu.Visibility  = Visibility.Hidden;
                Scroll_Notes.Visibility = Visibility.Hidden;
                var awaiter = Task.Delay(2500).GetAwaiter();
                awaiter.OnCompleted(() =>
                {
                    Hello_1.Visibility     = Visibility.Hidden;
                    Hello_2.Visibility     = Visibility.Hidden;
                    Scroll_Menu.Visibility = Visibility.Visible;


                    awaiter = Task.Delay(0).GetAwaiter();
                });
            }
        }
Ejemplo n.º 2
0
        private void Button_Click_Enter(object sender, RoutedEventArgs e)
        {
            string appDir = Environment.CurrentDirectory;
            string Opened = appDir + "/Sound/Opened.wav";
            string Error  = appDir + "/Sound/Error.wav";

            string emailUser = textBoxemail.Text;
            string loginUser = textBoxlogin.Text;
            string passUser  = textBoxpass.Password;

            DB db = new DB();

            DataTable table = new DataTable();

            MySqlDataAdapter adapter = new MySqlDataAdapter();

            db.openConnection();
            MySqlCommand command = new MySqlCommand("SELECT * FROM `users`WHERE `email`=@eU AND `login`=@lU ", db.getConnection());

            command.Parameters.Add("@eU", MySqlDbType.VarChar).Value = emailUser;
            command.Parameters.Add("@lU", MySqlDbType.VarChar).Value = loginUser;


            adapter.SelectCommand = command;
            adapter.Fill(table);

            if (table.Rows.Count > 0)
            {
                int sum = -1;

                MySqlCommand command2 = new MySqlCommand("SELECT `id`,`password` FROM `users` WHERE   email=@email  ", db.getConnection());
                command2.Parameters.Add("@email", MySqlDbType.VarChar).Value = emailUser;
                var hasher         = new SHA512Managed();
                var unhashed       = System.Text.Encoding.Unicode.GetBytes(passUser);
                var hashed         = hasher.ComputeHash(unhashed);
                var hashedPassword = Convert.ToBase64String(hashed);
                using (MySqlDataReader reader1 = command2.ExecuteReader())
                {
                    while (reader1.Read())
                    {
                        int id_user;
                        var id = reader1["id"].ToString();

                        id_user = int.Parse(id);
                        id_user = id_user % 88;
                        var tablepassword = reader1["password"].ToString();

                        tablepassword = tablepassword.Remove(id_user, 10);

                        if (tablepassword == hashedPassword)
                        {
                            sum = 1;
                        }
                        else
                        {
                            sum = 0;
                        }
                    }
                }
                if (sum == 1)
                {
                    _mpBgr.Open(new Uri(@Opened, UriKind.Absolute));
                    _mpBgr.Play();
                    Alarm.Visibility = Visibility.Hidden;
                    Security_Notes Security_Notes = new Security_Notes();
                    Security_Notes.Name.Text = textBoxlogin.Text;
                    this.Close();
                    Security_Notes.Show();
                    db.closeConnection();
                }
                else
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    Alarm.Text       = "Вы ввели не тот пароль!";
                    Alarm.Visibility = Visibility.Visible;
                }
            }
            else
            {
                db.closeConnection();
                _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                _mpBgr.Play();
                Alarm.Text       = "Вы либо ввели неправильные данные, либо не зарегистированы.";
                Alarm.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 3
0
        public void Button_Click_Check(object sender, RoutedEventArgs e)
        {
            string name       = textBoxname.Text.Trim();
            string secondname = textBoxsecondname.Text.Trim();
            string email      = textBoxemail.Text.Trim();
            string login      = textBoxlogin.Text.Trim();
            string pass       = textBoxpass.Password.Trim();
            string repeatpass = textBoxrepeatpass.Password.Trim();
            string post       = comboBoxpost.Text;


            string appDir = Environment.CurrentDirectory;
            string Opened = appDir + "/Sound/Opened.wav";
            string Error  = appDir + "/Sound/Error.wav";
            string Gun    = appDir + "/Sound/Gun.wav";
            string Exit   = appDir + "/Sound/Exit.wav";



            Boolean isUserExists()
            {
                DB db = new DB();

                DataTable table = new DataTable();

                MySqlDataAdapter adapter = new MySqlDataAdapter();

                MySqlCommand command = new MySqlCommand("SELECT * FROM `users`WHERE `name`=@N AND `secondname`=@sN AND `email`=@eU AND `post`=@PS", db.getConnection());

                command.Parameters.Add("@N", MySqlDbType.VarChar).Value  = textBoxname.Text;
                command.Parameters.Add("@sN", MySqlDbType.VarChar).Value = textBoxsecondname.Text;
                command.Parameters.Add("@eU", MySqlDbType.VarChar).Value = textBoxemail.Text;
                command.Parameters.Add("@PS", MySqlDbType.VarChar).Value = comboBoxpost.Text;

                adapter.SelectCommand = command;
                adapter.Fill(table);
                if (table.Rows.Count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            Boolean Check_login()
            {
                DB db = new DB();

                DataTable table = new DataTable();

                MySqlDataAdapter adapter = new MySqlDataAdapter();

                MySqlCommand command1 = new MySqlCommand("SELECT * FROM `users` WHERE `login`=@log", db.getConnection());

                command1.Parameters.Add("@log", MySqlDbType.VarChar).Value = textBoxlogin.Text;
                adapter.SelectCommand = command1;
                adapter.Fill(table);
                if (table.Rows.Count > 0)
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    Alarm.Text       = "Такой логин уже используется";
                    Alarm.Visibility = Visibility.Visible;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (post == "")
            {
                comboBoxpost.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                comboBoxpost.ToolTip    = "Это поле введено не корректно!";
                _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                _mpBgr.Play();
            }
            else
            {
                comboBoxpost.Background = new SolidColorBrush(Color.FromRgb(221, 221, 221));
                comboBoxpost.ToolTip    = "Это поле введено  корректно!";



                if (name != "")
                {
                    textBoxname.ToolTip    = "Это поле введено  корректно!";
                    textBoxname.Background = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                }
                else
                {
                    textBoxname.ToolTip    = "Это поле введено не корректно!";
                    textBoxname.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                }

                if (secondname != "")
                {
                    textBoxsecondname.ToolTip    = "Это поле введено  корректно!";
                    textBoxsecondname.Background = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                }
                else
                {
                    textBoxsecondname.ToolTip    = "Это поле введено не корректно!";
                    textBoxsecondname.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                }

                if (email == "")
                {
                    textBoxemail.ToolTip    = "Это поле введено не корректно!";
                    textBoxemail.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                }

                if (login == "")
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    textBoxlogin.ToolTip    = "Это поле введено не корректно!";
                    textBoxlogin.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                }

                if (pass == "")
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    textBoxpass.ToolTip    = "Это поле введено не корректно!";
                    textBoxpass.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                }

                if (repeatpass == "")
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    textBoxrepeatpass.ToolTip    = "Это поле введено не корректно!";
                    textBoxrepeatpass.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                }



                if (email.Length < 5)
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    textBoxemail.ToolTip    = "Это поле введено не корректно!";
                    textBoxemail.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                }
                else if (login.Length < 5 || login.Length > 15)
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    textBoxemail.ToolTip    = "Это поле введено  корректно!";
                    textBoxemail.Background = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxlogin.ToolTip    = "Это поле введено не корректно!";
                    textBoxlogin.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                }
                else if (pass.Length < 8 || !((pass.Contains("_") || (pass.Contains("@") || (pass.Contains("/") || (pass.Contains("#") || (pass.Contains("-"))))))))
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    textBoxlogin.ToolTip    = "Это поле введено  корректно!";
                    textBoxemail.Background = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxlogin.Background = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxpass.ToolTip     = "Это поле введено не корректно!";
                    textBoxpass.Background  = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                }
                else if (pass != repeatpass)
                {
                    _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                    _mpBgr.Play();
                    textBoxpass.ToolTip          = "Это поле введено  корректно!";
                    textBoxemail.Background      = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxlogin.Background      = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxpass.Background       = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxrepeatpass.ToolTip    = "Это поле введено не корректно!";
                    textBoxrepeatpass.Background = new SolidColorBrush(Color.FromRgb(204, 0, 0));
                }
                else
                {
                    textBoxname.Background       = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxsecondname.Background = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxemail.Background      = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxlogin.Background      = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxpass.Background       = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    textBoxrepeatpass.Background = new SolidColorBrush(Color.FromRgb(0, 220, 0));
                    comboBoxpost.Background      = new SolidColorBrush(Color.FromRgb(0, 220, 0));

                    if (isUserExists())
                    {
                        if (Check_login())
                        {
                        }
                        else
                        {
                            DB           db       = new DB();
                            MySqlCommand command  = new MySqlCommand("Update  `users` SET login=@log, password=@pass WHERE name=@name AND secondname=@secondname AND email=@email", db.getConnection());
                            MySqlCommand command2 = new MySqlCommand("SELECT `id` FROM `users` WHERE   email=@email1  ", db.getConnection());
                            command.Parameters.AddWithValue("@name", name);
                            command.Parameters.AddWithValue("@secondname", secondname);
                            command.Parameters.AddWithValue("@email", email);
                            command2.Parameters.Add("@email1", MySqlDbType.VarChar).Value = email;
                            db.openConnection();



                            using (MySqlDataReader reader = command2.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    var id      = reader["id"].ToString();
                                    int id_user = int.Parse(id);
                                    id_user = id_user % 88;
                                    string passnonhesh    = textBoxpass.Password;
                                    var    hasher         = new SHA512Managed();
                                    var    unhashed       = System.Text.Encoding.Unicode.GetBytes(passnonhesh);
                                    var    hashed         = hasher.ComputeHash(unhashed);
                                    var    hashedPassword = Convert.ToBase64String(hashed);
                                    hashedPassword = hashedPassword.Insert(id_user, Salt);
                                    command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = hashedPassword;
                                }
                            }

                            command.Parameters.Add("@log", MySqlDbType.VarChar).Value = textBoxlogin.Text;


                            db.openConnection();

                            if (command.ExecuteNonQuery() == 1)
                            {
                                Alarm.Visibility = Visibility.Hidden;
                                _mpBgr.Open(new Uri(@Gun, UriKind.Absolute));
                                _mpBgr.Play();
                                db.closeConnection();

                                this.Close();
                                MainWindow MainWindow = new MainWindow();
                                MainWindow.Show();
                            }
                            db.closeConnection();
                        }
                    }
                    else
                    {
                        _mpBgr.Open(new Uri(@Error, UriKind.Absolute));
                        _mpBgr.Play();
                        Alarm.Text       = "Вас либо нет в базе данных, либо вы неправильно ввели данные!Обращайтесь в поддержку.";
                        Alarm.Visibility = Visibility.Visible;
                    }
                }
            }
        }