private void updateComputerTableId() { DataBase dataBase = new DataBase(); //update database table id for the computer agent (if its exists) Definition.COMPUTER_TABLE_ID_DATABASE = dataBase.getComputerTableId(); }
private void EmptyAdmin() { DataBase dataBase = new DataBase(); //check if there is no agents (because it's the first use of the app or the database has been reset int numberAgent = dataBase.getNumberAgent(); if (numberAgent == -1) { MessageBox.Show("Vérifier les paramètres de connexion à la base de données"); return; } if (numberAgent != 0)// get the number of not deleted agent (computer agent excluded) { return; } //add default user for automatic task and admin using (var form = new AdminSetupBox())//get admin info { var result = form.ShowDialog(); if (result == DialogResult.OK) { //set admin short secure id SecureString short_secure_id_secureString = new SecureString(); String short_secure_id = SecurityManager.setAgentShortSecureId(); foreach (char c in short_secure_id) { short_secure_id_secureString.AppendChar(c); } short_secure_id_secureString.MakeReadOnly(); //get encrypted value string salt = DataProtection.getSaltForHashes(); string hash_password = DataProtection.getSaltHashedString(form.admin_password, salt); string encrypted_short_id = DataProtection.protect(short_secure_id_secureString); form.admin_password.Dispose(); short_secure_id_secureString.Dispose(); //add agents into the database Tools.Agent agent = new Tools.Agent(); //default agent for automatic use only agent.toDefault(); Random rand = new Random(); agent.lastName = "Poste"; agent.firstName = "Informatisé"; agent.id = Definition.COMPUTER_AUTHENTIFICATION_ID_DATABASE; agent.setRigth(-1); //add agent if (dataBase.addNewAgent(agent) != Definition.NO_ERROR_INT_VALUE) { MessageBox.Show("Impossible d'ajouter un nouvel agent"); return; } //update database table id for the computer agent Definition.COMPUTER_TABLE_ID_DATABASE = dataBase.getComputerTableId(); //add admin agent.toDefault(); agent.firstName = form.admin_firstName; agent.lastName = form.admin_lastName; agent.job = "DEUS EX"; agent.setRigth(0); agent.mailAdress = "none"; agent.id = form.admin_id; agent.hashedPassword = hash_password; agent.saltForHashe = salt; agent.shortSecureId = encrypted_short_id; //add agent if (dataBase.addNewAgent(agent) != Definition.NO_ERROR_INT_VALUE) { MessageBox.Show("Impossible d'ajouter un nouvel agent"); return; } MessageBox.Show("La création du compte administrateur s'est terminée avec succès.\nVotre identifiant est : " + form.admin_id); } else { MessageBox.Show("la création du compte administrateur a echouée"); return; } } }