コード例 #1
0
        public GUIManager()
        {
//            AppDomain.CurrentDomain.ProcessExit += DBManager.OnExit;

            Application.Initialize(ToolkitType.Gtk);

            // Initialize main window
            MainWindow = new GUIWindow()
            {
                Title     = "Password Manager",
                Width     = 500,
                Height    = 600,
                Resizable = true
            };

            LoggedIn = false;

            MainMenu = new Menu();

            // Creates the 'File' menu item
            MenuItem fileMenu = new MenuItem("File");

            fileMenu.SubMenu = new Menu();

            // Adds the 'Home' command to 'File' menu
            MenuItem homeCommand = new MenuItem(new Command("Home"));

            fileMenu.SubMenu.Items.Add(homeCommand);

            // Adds the 'Settings' command to 'File' menu
            MenuItem settingsCommand = new MenuItem(new Command("Settings"));

            fileMenu.SubMenu.Items.Add(settingsCommand);

            // Adds the 'Logout' command to 'File' menu
            MenuItem logoutCommand = new MenuItem(new Command("Logout"));

            fileMenu.SubMenu.Items.Add(logoutCommand);

            // Finalize fileMenu
            MainMenu.Items.Add((fileMenu));

            logoutCommand.Sensitive = false; // Change after logged in

            // Creates the 'Help' menu item
            MenuItem helpMenu = new MenuItem("Help");

            helpMenu.SubMenu = new Menu();

            // Adds 'About' item to 'Help' menu
            MenuItem aboutSubMenu = new MenuItem("About");

            helpMenu.SubMenu.Items.Add(aboutSubMenu);

            // Finalize helpMenu
            MainMenu.Items.Add(helpMenu);

            // Make login page
            LoginPage = new LoginPage(this);

            // Set buttons for window switching
            aboutSubMenu.Clicked += delegate
            {
                // Make about page
                AboutPage = new AboutPage(this);

                MainWindow.Content = AboutPage;
            };
            homeCommand.Clicked += delegate
            {
                // If not logged in, 'Home' sends to login page
                if (!LoggedIn)
                {
                    // Make login page
                    LoginPage = new LoginPage(this);

                    MainWindow.Content = LoginPage;
                }
                else // Else send to home page
                {
                    // Make management page
                    ManagementPage = new ManagementPage(this);

                    MainWindow.Content = ManagementPage;
                }
            };
            logoutCommand.Clicked += delegate
            {
                LoggedIn = false;

                DBManager.Instance.CloseDB();

                // Make login page
                LoginPage = new LoginPage(this);

                MainWindow.Content = LoginPage;
            };
            settingsCommand.Clicked += delegate
            {
                SettingsPage settingsPage = new SettingsPage(this);

                MainWindow.Content = settingsPage;
            };

            MainWindow.Content = LoginPage; // First page

            MainWindow.MainMenu = MainMenu;
        }
コード例 #2
0
        /// <summary>
        /// Login page
        /// </summary>
        /// <param name="gm">
        /// The manager
        /// </param>
        public LoginPage(GUIManager gm)
        {
            // Welcome title
            Label welcomeHeader = new Label("Welcome to Password Manager!")
            {
                Font          = this.Font.WithSize(16),
                TextAlignment = Alignment.Center,
                Wrap          = WrapMode.Word,
            };

            // Welcome message
            Label welcomeMessage =
                new Label("Your quick, simple local password storage device. Please login or create a user below to begin.")
            {
                Font          = this.Font.WithSize(10),
                TextAlignment = Alignment.Center,
                Wrap          = WrapMode.Word
            };

            this.Add(welcomeHeader, 0, 0, 2, 2, ExpandHorizontal  = true, ExpandVertical = false);
            this.Add(welcomeMessage, 0, 2, 2, 2, ExpandHorizontal = true, ExpandVertical = false);

            // Text for entries
            Label userLabel     = new Label("User:"******"Password:"******"Enter username..."
            };
            PasswordEntry passwordEntry = new PasswordEntry {
                PlaceholderText = "Enter password..."
            };

            this.Add(userEntry, 1, 4, 1, 1, ExpandHorizontal     = true, ExpandVertical = false);
            this.Add(passwordEntry, 1, 5, 1, 1, ExpandHorizontal = true, ExpandVertical = false);

            // Login button
            Button loginButton = new Button("Login");

            this.Add(loginButton, 0, 6, 1, 1, ExpandHorizontal = true, ExpandVertical = false);

            // Create user button
            Button createUserButton = new Button("Create User");

            this.Add(createUserButton, 1, 6, 1, 1, ExpandHorizontal = true, ExpandVertical = false);

            loginButton.Clicked += delegate
            {
                gm.LoggedIn = true;

                // Get entered text
                string user     = userEntry.Text;
                string password = passwordEntry.Password;

                if (!GUIManager.IsValid(user) || !GUIManager.IsValid(password))
                {
                    // Not a valid user or password
                    MessageDialog.ShowError("Please do not enter empty values, whitespace, or '\\' in the entries!");
                    return;
                }

                // Ensure user exists
                if (!DBManager.Instance.DBExists(user))
                {
                    MessageDialog.ShowError("User with the given name does not exist.");
                    return;
                }

                // Log in
                switch (DBManager.Instance.OpenDB(user, password))
                {
                case 0:
                    MessageDialog.ShowError("Incorrect password provided.");
                    return;

                case 2:
                    MessageDialog.ShowError("No password hash file was found! Database cannot be decrypted.");
                    return;

                case 3:
                    MessageDialog.ShowError("Database open failed.");
                    return;

                case 4:
                    MessageDialog.ShowError("No database found and failed to create one. This should be impossible.");
                    return;
                }

                // Make management page
                ManagementPage managementPage = new ManagementPage(gm);

                // In here, check for username/password validation and log in
                gm.MainWindow.Content = managementPage;
            };
            createUserButton.Clicked += delegate
            {
                gm.LoggedIn = true;

                // Get entered text
                string user     = userEntry.Text;
                string password = passwordEntry.Password;

                if (!GUIManager.IsValid(user) || !GUIManager.IsValid(password))
                {
                    // Not a valid user or password
                    MessageDialog.ShowError("Please do not enter empty values, whitespace, or '\\' in the entries!");
                    return;
                }

                // Don't allow overwriting users
                if (DBManager.Instance.DBExists(user))
                {
                    MessageDialog.ShowError("User with the given name already exists.");
                    return;
                }

                // Log in
                switch (DBManager.Instance.OpenDB(user, password))
                {
                case 0:
                    MessageDialog.ShowError("Incorrect password provided. This makes no sense.");
                    return;

                case 2:
                    MessageDialog.ShowError("No password hash file was found! Database cannot be decrypted. This makes no sense.");
                    return;

                case 3:
                    // This shouldn't happen
                    MessageDialog.ShowError("Our encryption scheme is broken!");
                    return;

                case 4:
                    MessageDialog.ShowError("No database found and failed to create one. This should be impossible.");
                    return;
                }

                // Make management page
                ManagementPage managementPage = new ManagementPage(gm);

                // In here, check for username/password validation and log in
                gm.MainWindow.Content = managementPage;
            };

            gm.SetLogoutButton();
        }