private async void editButton_Click(object sender, EventArgs e)
        {
            if (this.passwordTextBox.ReadOnly)
            {
                this.passwordTextBox.ReadOnly = false;
                this.editButton.Text          = "Submit";
            }
            else
            {
                this.passwordTextBox.ReadOnly = true;
                this.editButton.Text          = "Edit";

                // Assumption: The selected node is capable of having a parent (since it's
                // the app node).
                var selectedNode = this.applicationTreeView.SelectedNode;
                var username     = selectedNode.Text;
                var appName      = selectedNode.Parent.Text;
                var appType      = selectedNode.Parent.Parent.Text;

                var encryptedPw = Shared.CryptManager.encrypt(this.passwordTextBox.Text, M_secretkey);

                var app     = new Shared.Application(appName, new Shared.Username[] { new Shared.Username(username, encryptedPw) }, appType);
                var request = new PasswordRequest(app);
                request.updatePassword = true;

                var response = await SocketManager.Instance.SendRequest <PasswordResponse>(request);

                var password = Shared.CryptManager.decrypt(response.application.Usernames[0].password, M_secretkey);
                this.fillPasswordBox(password);
            }
        }
Example #2
0
        public bool editApp(Shared.Application appToEdit, string newName, string newAppType, string user)
        {
            try
            {
                String sqlString = "UPDATE APPLICATIONS set application_type = @newAppType, application = @newAppName" +
                                   " WHERE name = @user AND username = @username AND application = @oldAppName";
                SQLiteCommand command = new SQLiteCommand(sqlString, dbConnection);
                command.Parameters.AddWithValue("@newAppType", newAppType);
                command.Parameters.AddWithValue("@newAppName", newName);
                command.Parameters.AddWithValue("@user", user);
                command.Parameters.AddWithValue("@oldAppName", appToEdit.Name);
                var usernames = appToEdit.Usernames;
                foreach (var name in usernames)
                {
                    command.Parameters.AddWithValue("@username", name.name);
                    command.ExecuteNonQuery();
                }

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Example #3
0
        private async void submitButton(object sender, EventArgs e)
        {
            try
            {
                Shared.Application app         = new Shared.Application();
                String             plainTextPw = pwTextBox.Text;
                var               encryptedPw  = Shared.CryptManager.encrypt(plainTextPw, secretKey);
                Shared.Username   username     = new Shared.Username(usernameTextBox.Text, encryptedPw);
                Shared.Username[] userName     = new Shared.Username[] { username };
                app.Usernames = userName;
                app.Type      = appTypeComboBox.Text;
                app.Name      = appNameTextBox.Text;
                NewAppRequest request  = new NewAppRequest(app);
                var           response = await SocketManager.Instance.SendRequest <NewAppResponse>(request);

                this.managerForm.addAppToTree(response.application);
                this.Close();
            }
            catch (ResponseException ex)
            {
                using (var details = new TaskDialog()
                {
                    Caption = "Cannot Add User",
                    InstructionText = "Unable to add this application and user",
                    Text = ex.Message,
                    Icon = TaskDialogStandardIcon.Error,
                    StandardButtons = TaskDialogStandardButtons.Close
                })
                {
                    details.Show();
                }
            }
        }
        public void addAppToTree(Shared.Application application)
        {
            var rootNodes = getRootNodes();

            TreeNode theAppTypeNode = null;
            TreeNode theAppNode     = null;

            // First, search for the existing app type node and the app node in the TreeView.
            foreach (var appTypeNode in rootNodes)
            {
                if (application.Type == appTypeNode.Text)
                {
                    theAppTypeNode = appTypeNode;

                    foreach (TreeNode appNode in appTypeNode.Nodes)
                    {
                        if (application.Name == appNode.Text)
                        {
                            theAppNode = appNode;
                            break;
                        }
                    }
                }
            }

            // Create the root node (i.e., the app type node) if our search ended up fruitless
            if (theAppTypeNode == null)
            {
                theAppTypeNode                  = new TreeNode(application.Type);
                theAppTypeNode.ImageKey         = "AppType";
                theAppTypeNode.SelectedImageKey = "AppType";
                this.applicationTreeView.Nodes.Add(theAppTypeNode);
            }

            // Create the app node if our search ended up fruitless
            if (theAppNode == null)
            {
                theAppNode                  = new TreeNode(application.Name);
                theAppNode.ImageKey         = "AppName";
                theAppNode.SelectedImageKey = "AppName";
                theAppTypeNode.Nodes.Add(theAppNode);
            }

            // Now add the username underneath theAppNode
            foreach (var username in application.Usernames)
            {
                var userNode = theAppNode.Nodes.Add(username.name);
                userNode.ImageKey         = "AppUser";
                userNode.SelectedImageKey = "AppUser";
            }
        }
        public void deleteUsername(Shared.Application appUser)
        {
            var rootNodes = getRootNodes();

            foreach (var appTypeNode in rootNodes)
            {
                if (appUser.Type == appTypeNode.Text)
                {
                    foreach (TreeNode appNode in appTypeNode.Nodes)
                    {
                        if (appUser.Name == appNode.Text)
                        {
                            foreach (TreeNode userNode in appNode.Nodes)
                            {
                                if (appUser.Usernames[0].name == userNode.Text)
                                {
                                    userNode.Remove();

                                    // While we're add it, delete the app and the app type if this
                                    // was the only username and app remaining.
                                    if (appNode.Nodes.Count == 0)
                                    {
                                        appNode.Remove();
                                    }

                                    if (appTypeNode.Nodes.Count == 0)
                                    {
                                        appTypeNode.Remove();
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            }

            // Reset the selection, in case the username we've deleted is the currently selected node
            if (this.applicationTreeView.SelectedNode == null)
            {
                this.passwordTextBox.Enabled    = false;
                this.showpwCheckBox.Enabled     = false;
                this.buttonDelete.Enabled       = false;
                this.passwordCopyButton.Enabled = false;
                this.editButton.Enabled         = false;
                this.passwordTextBox.Text       = string.Empty;
            }
        }
Example #6
0
        /**
         * @brief
         *      gets all the applications for a specific user
         */
        public Shared.Application [] getApplications(String user)
        {
            String[] applicationNames = getApplicationNames(user);
            List <Shared.Application> applications = new List <Shared.Application>();

            foreach (var name in applicationNames)
            {
                String             appType   = getAppType(name, user);
                Shared.Username[]  usernames = getUserNames(name, user);
                Shared.Application app       = new Shared.Application(name, usernames, appType);
                applications.Add(app);
            }

            return(applications.ToArray());
        }
        public EditApplicationForm(string[] appTypes, Shared.Application app)
        {
            InitializeComponent();

            // Populate the application type combo box with all the types the user has so far
            foreach (var appType in appTypes)
            {
                if (!this.appTypeComboBox.Items.Contains(appType))
                {
                    this.appTypeComboBox.Items.Insert(0, appType);
                }
            }

            this.appNameTextBox.Text  = app.Name;
            this.appTypeComboBox.Text = app.Type;
        }
Example #8
0
 /**
  * @brief
  *      removes a username and his info from the database.
  *
  */
 public bool removeUsername(Shared.Application app, String user)
 {
     try{
         String        sqlString = "DELETE FROM applications WHERE name = @name AND application = @appname AND username = @username";
         SQLiteCommand command   = new SQLiteCommand(sqlString, dbConnection);
         command.Parameters.AddWithValue("@name", user);
         command.Parameters.AddWithValue("@appName", app.Name);
         command.Parameters.AddWithValue("@username", app.Usernames[0].name);
         command.ExecuteNonQuery();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Example #9
0
 /**
  * @brief
  *      sets the password for a specific username under the specific user
  *      NOTE: the password should be encrypted
  */
 public bool setPassword(Shared.Application app, String user)
 {
     try{
         String        sqlString = "UPDATE applications SET password = @password WHERE application = @appName AND username = @username AND name = @user";
         SQLiteCommand command   = new SQLiteCommand(sqlString, dbConnection);
         command.Parameters.AddWithValue("@user", user);
         command.Parameters.AddWithValue("@appName", app.Name);
         command.Parameters.AddWithValue("@username", app.Usernames[0].name);
         command.Parameters.AddWithValue("@password", app.Usernames[0].password);
         command.ExecuteNonQuery();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Example #10
0
 public bool changeUsername(Shared.Application app, string newUsername, string user)
 {
     try
     {
         string sqlString = "UPDATE APPLICATIONS set username = @newUsername " +
                            " WHERE name = @user AND application = @appname AND username = @username";
         SQLiteCommand command = new SQLiteCommand(sqlString, dbConnection);
         command.Parameters.AddWithValue("@newUsername", newUsername);
         command.Parameters.AddWithValue("@user", user);
         command.Parameters.AddWithValue("@appname", app.Name);
         command.Parameters.AddWithValue("@username", app.Usernames[0].name);
         command.ExecuteNonQuery();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Example #11
0
 /**
  * @brief
  *      adds a new username to the database fields in all of the parameters
  *      in the applications table
  */
 public bool addUsername(Shared.Application app, String user)
 {
     try
     {
         String sqlString = "INSERT INTO applications (name, application, application_type, username, password) " +
                            "VALUES (@name, @appName, @appType, @username, @password)";
         SQLiteCommand command = new SQLiteCommand(sqlString, dbConnection);
         command.Parameters.AddWithValue("@name", user);
         command.Parameters.AddWithValue("@appName", app.Name);
         command.Parameters.AddWithValue("@appType", app.Type);
         command.Parameters.AddWithValue("@username", app.Usernames[0].name);
         command.Parameters.AddWithValue("@password", app.Usernames[0].password);
         command.ExecuteNonQuery();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Example #12
0
 public bool changeAppType(Shared.Application app, string user)
 {
     try
     {
         String        sqlString = "UPDATE APPLICATIONS set application_type = @application_type WHERE application = @application AND name = @name AND username = @username";
         SQLiteCommand command   = new SQLiteCommand(sqlString, dbConnection);
         command.Parameters.AddWithValue("@application", app.Name);
         command.Parameters.AddWithValue("application_type", app.Type);
         command.Parameters.AddWithValue("@name", user);
         foreach (var username in app.Usernames)
         {
             command.Parameters.AddWithValue("@username", username.name);
             command.ExecuteNonQuery();
         }
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
 public PasswordRequest(Shared.Application app) :
     base(MessageID, MessageType.Request)
 {
     application = app;
 }
 public PasswordResponse(Shared.Application app) :
     base(MessageID, MessageType.Response)
 {
     application = app;
 }
Example #15
0
 public NewAppRequest(Shared.Application app) :
     base(MessageID, MessageType.Request)
 {
     application = app;
 }
 public EditApplicationRequest(Shared.Application application) :
     base(MessageID, MessageType.Request)
 {
     AppToEdit = application;
 }
Example #17
0
 public NewAppResponse(Shared.Application app) :
     base(MessageID, MessageType.Response)
 {
     application = app;
 }
Example #18
0
 public DeleteUsernameRequest(Shared.Application app) :
     base(MessageID, MessageType.Request)
 {
     application = app;
 }
 public ChangeAppTypeRequest(Shared.Application application) :
     base(MessageID, MessageType.Request)
 {
     apps = new Shared.Application [] { application };
 }
 public EditUsernameRequest(Shared.Application application) :
     base(MessageID, MessageType.Request)
 {
     app = application;
 }