Ejemplo n.º 1
0
        private void EditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            MD5 md5Hash = MD5.Create();
            var x       = dataGrid.ItemsSource.ToList <User>().ToList().Select(c => c.Login);

            if (e.Column.Header.ToString() == "Login")
            {
                if (x.Contains(((TextBox)e.EditingElement).Text))
                {
                    MessageBox.Show("Such login already exists");
                    ((TextBox)e.EditingElement).Text = "";
                    e.Cancel = true;
                    return;
                }
                return;
            }
            else if (e.Column.Header.ToString() == "Password")
            {
                ((TextBox)e.EditingElement).Text = GetMd5.GetMd5Hash(md5Hash, ((TextBox)e.EditingElement).Text);
            }
        }
Ejemplo n.º 2
0
 private void Change(object sender, RoutedEventArgs e)
 {
     if (password.Password == confirmpassword.Password)
     {
         MD5 md5Hash = MD5.Create();
         Users.Remove(Users.Find((c) => c.Login == User.Login));
         Users.Add(new User {
             Login = User.Login, Password = GetMd5.GetMd5Hash(md5Hash, password.Password), Role = User.Role
         });
         using (var sw = new StreamWriter(@"users.txt"))
         {
             foreach (var item in Users)
             {
                 sw.WriteLine(item.Login + ":" + item.Password + ":" + item.Role);
             }
         }
         Close();
     }
     else
     {
         MessageBox.Show("Passwords do not match");
     }
 }
Ejemplo n.º 3
0
        private void Enter(object sender, RoutedEventArgs e)
        {
            var users = new List <User>();

            if (login.Text == "admin" && password.Password == "admin")
            {
                AdminMain adminMain = new AdminMain(
                    new User
                {
                    Login    = login.Text,
                    Password = password.Password,
                    Role     = 1
                });
                adminMain.Show();
                Close();
                return;
            }
            try
            {
                foreach (string str in File.ReadAllLines(@"users.txt"))
                {
                    if (str == "")
                    {
                        continue;
                    }
                    var userinstr = str.Split('|');

                    users.Add(
                        new User
                    {
                        Login         = userinstr[0],
                        Password      = userinstr[1],
                        Role          = byte.Parse(userinstr[2]),
                        Even          = bool.Parse(userinstr[3]),
                        From          = DateTime.Parse(userinstr[4]),
                        To            = DateTime.Parse(userinstr[5]),
                        FromTime      = int.Parse(userinstr[6]),
                        ToTime        = int.Parse(userinstr[7]),
                        ForbiddenList = userinstr[8].Split('?').ToList()
                    });
                }
            }
            catch (Exception ex) { }
            bool found = false;

            foreach (var item in users)
            {
                if (item.Login == login.Text)
                {
                    MD5 md5Hash = MD5.Create();
                    if (item.Password == GetMd5.GetMd5Hash(md5Hash, password.Password))
                    {
                        found = true;
                        if (DateTime.Now.Day % 2 != 0 && item.Even)
                        {
                            MessageBox.Show("Today is an odd day. \nYour day is tomorrow");
                            return;
                        }
                        else if (DateTime.Now.Day % 2 == 0 && !item.Even)
                        {
                            MessageBox.Show("Today is an even day. \nYour day is tomorrow");
                            return;
                        }
                        if (item.To.Day * 86400 + item.ToTime * 3600 < DateTime.Now.Day * 86400 + DateTime.Now.Hour * 3600 + DateTime.Now.Second)
                        {
                            MessageBox.Show(string.Format("Access is denied.\n Your terms from {0}/{1}/{2}  {3}:00 to {4}/{5}/{6} {7}:00",
                                                          item.From.Day, item.From.Month, item.From.Year, item.FromTime, item.To.Day, item.To.Month, item.To.Year, item.ToTime));
                            return;
                        }
                        if (item.Role == 0)
                        {
                            Menu menu = new Menu(item, false);
                            menu.Show();
                        }
                        if (item.Role == 1)
                        {
                            AdminMain adminMain = new AdminMain(item);
                            adminMain.Show();
                        }
                        Close();
                    }
                }
            }

            if (!found)
            {
                MessageBox.Show("Incorrect Login or Password");
            }
        }
Ejemplo n.º 4
0
        private void Add(object sender, RoutedEventArgs e)
        {
            var users = new List <User>();

            try
            {
                var temp = File.ReadAllLines(@"users.txt");
                foreach (string str in File.ReadAllLines(@"users.txt"))
                {
                    if (str == "")
                    {
                        continue;
                    }
                    var userinstr = str.Split('|');
                    users.Add(
                        new User
                    {
                        Login    = userinstr[0],
                        Password = userinstr[1],
                        Role     = byte.Parse(userinstr[2])
                    });
                }
            }
            catch (Exception ex) { }
            var x = users.Select(c => c.Login);

            if (x.Contains(login.Text))
            {
                MessageBox.Show("Such login already exists");
                return;
            }
            int fromTime = 0;
            int toTime   = 24;

            if (!int.TryParse(fromtime.Text, out fromTime) || !int.TryParse(totime.Text, out toTime) || fromTime < 0 || toTime > 24)
            {
                MessageBox.Show("The entered time is incorrect");
                return;
            }

            int.TryParse(totime.Text, out toTime);
            if (String.IsNullOrEmpty(login.Text) || String.IsNullOrEmpty(password.Password) || from.SelectedDate == null || to.SelectedDate == null)
            {
                MessageBox.Show("The entered data is incorrect");
            }
            else
            {
                MD5 md5hash = MD5.Create();
                User = new User
                {
                    Login         = login.Text,
                    Password      = GetMd5.GetMd5Hash(md5hash, password.Password),
                    Role          = 0,
                    Even          = even.IsChecked.Value,
                    From          = from.SelectedDate.Value.AddHours(-12),
                    To            = to.SelectedDate.Value.AddHours(-12),
                    FromTime      = fromTime,
                    ToTime        = toTime,
                    ForbiddenList = _forbidden
                };
                Close();
            }
        }