private User login(User loginUser) { User user = repositoryUser.FindAll(x => x.Login == loginUser.Login && x.Password == loginUser.Password).FirstOrDefault(); if (user == null) { user = new User(); user.Id = -1; } else { user.Groups.ToString(); } return(user); }
private void button1_Click(object sender, EventArgs e) { var username = textBox1.Text; var pwd = textBox2.Text; if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(pwd)) { MessageBox.Show("Enter login and Password", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var users = repositoryUser.FindAll(u => u.Login.Equals(username)); var user = users.FirstOrDefault(); this.user = user; if (users.Count() != 0 && user.Password.Equals(pwd)) { MessageBox.Show("Вітаємо,авторизація пройдена"); } else { MessageBox.Show("Невірний пароль або логін"); return; } if (user == null) { MessageBox.Show("User not found", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!user.isAdmin) { MessageBox.Show("Access denired", "Access", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { Main_Form main_Form = new Main_Form(user); main_Form.ShowDialog(); } }