Пример #1
0
        // login logic
        private void LoginExecute(PasswordBox passBox)
        {
            var userList = (from u in _ctx.Users
                select new {u.Id, u.Login, u.Password,u.AccountPrivileges.AccountType}
                ).ToList();
            if (userList.Any())
            {
                foreach (var user in userList)
                {
                    //(user.Password == ShaConverter.sha256_hash(passBox.Password))\
                    if (user.Login == _userLogin && user.Password == passBox.Password)
                    {

                        _userId = user.Id;
                        _userType = user.AccountType;

                        MessageBox.Show("Otworz nowe okno \n" +
                                        "Zamknij obecne");
                        _allowToLog = true;
                        break;
                    }
                }
            }

            if (_allowToLog)
            {
                // Application.Current.MainWindow
                MessageBox.Show("Zmien domyslne okno logowania na nowe lub je .hide");
            }
            else
            {
                MessageBox.Show("Podana nazwa użytkownika i/lub hasło jest niepoprawne!" +
                                "Spróbuj ponownie!");
                UserLogin = string.Empty;
                passBox.Clear();
            }
        }
        private void ResetExecute(PasswordBox passBox)
        {
            UserName = "";
            passBox.Clear();
            Broker = ConfigurationManager.AppSettings["DefaultBroker"];

            ProjectList = null;

            TopFieldsEnabled = true;
        }
Пример #3
0
        public void procedureAuthenticateLocally()
        {
            if (client.SessionVariables.IsAuthenticated)
            {
                return;
            }
            //string endpoint = "";
            string ip = client.IP;// endpoint.Substring(0, endpoint.IndexOf(':'));

            if (myTcpServer.Blocked.Contains(ip))
            {
                return; // should soon die. This is the clientveiw list being destroyed before the clienttbale in tcpserver
            }
            Action acceptClient = () =>
            {
                HttpAuth.allowClient(client, "Default");
                HttpResponse response = new HttpResponse(HttpResponse.ConnectionStatus.FOUND, "keep-alive", null);
                response.addHeader("Content-Length", "0");
                response.addHeader("Location", "/controllers");
                App.Log.logEvent(response.ToString(), Event.EVENT_FLAGS.DEBUG);
                try
                {
                    SocketWriteLine(response.ToString());
                }
                catch (IOException ex)
                {
                    App.Log.logEvent("IOException serving page to : " + client.ToString() + "\r\n Stack:" + ex.StackTrace, Event.EVENT_FLAGS.IMPORTANT | Event.EVENT_FLAGS.CRITICAL);
                }
            };

            App.Current.Dispatcher.BeginInvoke(
                new Action(() =>
            {
                PasswordBox pass = new System.Windows.Controls.PasswordBox()
                {
                    FlowDirection = FlowDirection.LeftToRight, Foreground = Brushes.White, CaretBrush = Brushes.White, Margin = new Thickness(10, 0, 0, 0), Height = 20, Width = 200
                };
                TextBlock lblpass = new System.Windows.Controls.TextBlock()
                {
                    FlowDirection = System.Windows.FlowDirection.LeftToRight, TextWrapping = System.Windows.TextWrapping.NoWrap, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Margin = new Thickness(10, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Style = (Style)App.MainWin.FindResource("HeadingWhiteShadowBold"), Text = "Please enter your password then hit enter to ALLOW:", Foreground = Brushes.Gold
                };
                MessageBox thisMessageBox = new MessageBox("A device: " + client.EndPoint + " is trying to authenticate. Give permission to access Controllers?", "Local Authentication");

                pass.KeyDown += delegate(object sender, System.Windows.Input.KeyEventArgs e)
                {
                    if (e.Key == System.Windows.Input.Key.Enter)
                    {
                        byte[] passtry = new System.Security.Cryptography.SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(pass.Password));
                        if (App.Config.password.SequenceEqual(passtry))
                        {
                            acceptClient.Invoke();
                            thisMessageBox.Close();
                        }
                        else
                        {
                            lblpass.Foreground = Brushes.Red;
                            lblpass.Text       = "Incorrect password. Please try again.";
                        }
                        pass.Clear();
                    }
                };
                //lblpass.KeyDown += Allow_Try;

                thisMessageBox.addButton("Deny Once", Deny_Click);
                thisMessageBox.addButton("Block Device", delegate()
                {
                    myTcpServer.tempBanIP(client.IP);
                });
                if (App.Config.username == null || App.Config.username == "")
                {
                    thisMessageBox.addButton("Accept", acceptClient, true);
                    lblpass.Text = "Log in to password protect this prompt.";
                }
                else
                {
                    thisMessageBox.ButtonPannel.Children.Add(pass);
                }
                thisMessageBox.ButtonPannel.Children.Add(lblpass);
                thisMessageBox.Width = 720;
                thisMessageBox.Show();
                pass.Focus();


                //MessageBox thisMessageBox = new MessageBox();
                //thisMessageBox.addButton("Deny", Deny_Click);
                //thisMessageBox.addButton("Allow", Allow_Click);
                //thisMessageBox.Show();
                //thisMessageBox.Focus();
                //thisMessageBox.bringForward();
            }));
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //(old)
            //if (System.Windows.MessageBox.Show("A device: " + client.IP + " is trying to authenticate. Give permission to access Controllers?","Local Authentication",System.Windows.MessageBoxButton.YesNo) == System.Windows.MessageBoxResult.Yes)
            //{
            //    HttpAuth.authenticateClient(client);
            //}
            //else
            //{
            //    client.SessionVariables.IsAuthenticated = false;
            //}
        }
Пример #4
0
        // login logic
        private void LoginExecute(PasswordBox passBox)
        {
            try
            {
                var userToLogin = (from u in _ctx.Users
                    where u.Login == _userLogin
                    select u);

                // jeżeli w bazie jest tylko jeden użytkownik o podanej nazwie użytkownika oraz jest to jego pierwsze logowanie
                if (userToLogin.Count() == 1 && userToLogin.SingleOrDefault().FirstLogin.ToUpper() == "T")
                {
                    if (PasswordValidator.ValidatePassword(passBox.Password))
                    {
                        //.Password = passBox.Password;
                        userToLogin.First().Password = ShaConverter.sha256_hash(passBox.Password);    // przypisz do konta użytkownika wpisane przez niego hasło
                        userToLogin.First().FirstLogin = "******";   // zmień tryb logowania
                        UserId = userToLogin.First().Id;    // przypisz Id użytkownika w celu umożliwienia jego jednoznacznej identyfikacji
                        _userType = userToLogin.First().AccountPrivileges.AccountType;  // uzyskaj typ konta użytkownika znajdujący się w bazie danych
                        _ctx.SaveChanges(); // zapisz zmiany
                        _allowToLog = true; // umożliwienie zalogowania się
                        _isWrongPassword = false;
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Hasło musi zawierac przynajmniej 8 znaków w tym przynajmniej jedną dużą literę, małą literę oraz cyfrę. " +
                            Environment.NewLine + "Spróbuj ponownie!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                        _isWrongPassword = true;
                    }
                }
                //.Password == passBox.Password)
                // jeśli w bazie jest tylko jeden użytkownik o podanej nazwie użytkownika oraz podana nazwa konta oraz przypisane do niego hasło jest poprawne
                else if (userToLogin.Count() == 1 && userToLogin.First().Login == _userLogin && userToLogin.First().Password == ShaConverter.sha256_hash(passBox.Password))
                {
                    _userType = userToLogin.First().AccountPrivileges.AccountType;
                    UserId = userToLogin.First().Id;
                    _allowToLog = true;
                }
                // jeżli użytkownik otrzymał dostęp do logowania
                if (_allowToLog && _isWrongPassword == false)
                {
                    // w zależności od typu konta uruchom okno główne
                    if (_userType.ToUpper() == "A")
                    {
                        AdminMainView adminMainView = new AdminMainView(_userId);
                        adminMainView.Show();
                        Application.Current.MainWindow.Hide();
                    }
                    else if(_userType.ToUpper() == "S")
                    {
                        UserMainView userMainView = new UserMainView(_userId);
                        userMainView.Show();
                        Application.Current.MainWindow.Hide();
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Błędny typ konta usera", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    if (_isWrongPassword)
                    {
                        passBox.Clear();
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Podana nazwa użytkownika i/lub hasło jest niepoprawne!" + Environment.NewLine +
                                        "Spróbuj ponownie!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                        UserLogin = string.Empty;
                        passBox.Clear();
                    }

                }
            }
            catch (Exception ex)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Błąd połączenia z bazą danych. Skontaktuj się z administratorem.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);

                //MessageBox.Show(ex.ToString());
                //MessageBox.Show("Błąd połączenia z bazą danych. Skontaktuj się z administratorem.");
            }
        }