protected override void Seed(SecurityContext context)
 {
     context.Users.Add(new Models.User
     {
         Login    = "******",
         Password = DataEncryptor.HashPassword("123")
     });
 }
Exemplo n.º 2
0
 protected override void Seed(SecurityContext context)
 {
     context.Users.Add(new Models.User
     {
         Login    = "******",
         Name     = "Ben",
         Password = DataEncryptor.HashPassword("Qwerty@99"),
         Email    = "*****@*****.**",
         Phone    = "+77011012030"
     });
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new SecurityContext())
            {
                context.Users.Add(new Models.User
                {
                    Login    = loginTextBox.Text,
                    Password = DataEncryptor.HashPassword(passordBox.Password)
                });

                MessageBox.Show("Вы зарегестрированы!");
            }
        }
Exemplo n.º 4
0
        private void RegistrationButtonClick(object sender, RoutedEventArgs e)
        {
            var login    = loginTextBox.Text;
            var password = passwordTextBox.Text;

            if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) ||
                string.IsNullOrWhiteSpace(login) || string.IsNullOrWhiteSpace(password))
            {
                MessageBox.Show("Заполните все поля");
                return;
            }

            using (var context = new UsersContext())
            {
                List <User> users = context.Users.ToList();
                int         choce = 0;

                foreach (var u in users)
                {
                    if (u.Login == login)
                    {
                        MessageBox.Show("Логин существует, авторизуйтесь");
                        ++choce;
                        break;
                    }
                }

                if (choce == 0)
                {
                    context.Users.Add
                    (
                        new User
                    {
                        Login    = login,
                        Password = DataEncryptor.HashPassword(password)
                    }
                    );
                    context.SaveChanges();
                    MessageBox.Show("Логин успешно зарегистрирован!");
                    loginTextBox.Clear();
                    passwordTextBox.Clear();
                }
            }
        }
Exemplo n.º 5
0
        private void RegisterButtonClick(object sender, RoutedEventArgs e)
        {
            var login          = registrationLoginTextBox.Text;
            var password       = registrationPasswordBox.Password;
            var repeatPassword = registrationRepeatPasswordBox.Password;

            if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(repeatPassword))
            {
                MessageBox.Show("Заполните все поля");
                return;
            }

            if (password != repeatPassword)
            {
                MessageBox.Show("Введенные пароля не совпадают");
                return;
            }

            using (var context = new UserContext())
            {
                if (context.Users.All(user => user.Login != login))
                {
                    User newUser = new User()
                    {
                        Login    = login,
                        Password = DataEncryptor.HashPassword(password)
                    };

                    context.Users.Add(newUser);
                    context.SaveChanges();

                    MessageBox.Show("Успешная регистрация");
                }
                else
                {
                    MessageBox.Show("Логин занят");
                }
            }
        }
Exemplo n.º 6
0
        private void RegistrationButton_Click(object sender, RoutedEventArgs e)
        {
            User user = new User(
                loginTextBox.Text, nameTextBox.Text, lastNameTextBox.Text,
                passwordBox.Password, emailTextBox.Text, phoneTextBox.Text);
            string confirmPassword = confirmPasswordBox.Password;

            var results = new List <ValidationResult>();
            var context = new ValidationContext(user);

            SortedList <string, object> verifiableProperties = new SortedList <string, object> {
                { "Login", user.Login },
                { "Email", user.Email },
                { "Phone", user.Phone }
            };

            UsersRepository repository = new UsersRepository();

            foreach (var property in verifiableProperties)
            {
                if (repository.CheckForAvailability(property.Key, property.Value) != null)
                {
                    results.Add(new ValidationResult(property.Key + " уже занят(-а)"));
                }
            }

            Label[] labels = new Label[]
            {
                nameLabel, loginLabel, passwordLabel, confirmPasswordLabel, emailLabel, phoneLabel
            };

            TextBox[] textBoxes = new TextBox[]
            {
                nameToolTextBox, loginToolTextBox, passwordToolTextBox, confirmPasswordToolTextBox, emailToolTextBox, phoneToolTextBox
            };

            string[] properties =
            { "Имя",      "Логин", "Пароль",   "Пароли",    "Почта", "Телефонный номер",
              "Name", "Login", "Password", "Passwords", "Email", "Phone" };

            string passwordPattern = @"(?=^.{6,32}$)((?=.*\d)(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$";

            if (user.Password != confirmPassword || confirmPassword.Length == 0)
            {
                results.Add(new ValidationResult("Пароли не совпадают"));
            }
            if (user.Password.Length < 6 || user.Password.Length > 32)
            {
                results.Add(new ValidationResult("Пароль должен состоять мин. из 6 символов и макс. из 32 символов"));
            }
            else if (!(Regex.IsMatch(user.Password, passwordPattern)))
            {
                results.Add(new ValidationResult("Пароль должен содержать цифровой и спец символы, а также буквы верхнего, нижнего регистра"));
            }

            var converter = new System.Windows.Media.BrushConverter();

            if (!Validator.TryValidateObject(user, context, results, true) || results.Count > 0)
            {
                for (int i = 0; i < labels.Length; i++)
                {
                    foreach (var result in results)
                    {
                        if (result.ErrorMessage.Contains(properties[i]) ||
                            result.ErrorMessage.Contains(properties[i + labels.Length]))
                        {
                            textBoxes[i].Text = result.ErrorMessage;
                            labels[i].Content = result.ErrorMessage;
                            var brush = (Brush)converter.ConvertFromString("Red");
                            labels[i].Background = brush;
                            break;
                        }
                        else
                        {
                            var brush = (Brush)converter.ConvertFromString("LightBlue");
                            labels[i].Background = brush;
                            textBoxes[i].Text    = "Одобрено";
                            labels[i].Content    = "Одобрено";
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < labels.Length; i++)
                {
                    var brush = (Brush)converter.ConvertFromString("Green");
                    labels[i].Background = brush;
                    labels[i].Content    = "Успешно";
                    if (lastNameTextBox.Text.Length == 0)
                    {
                        user.LastName = null;
                    }
                    user.Password = DataEncryptor.HashPassword(confirmPassword);
                    repository.Insert(user);
                    Close();
                }
            }
        }