jorabin / KeePassJava2

Java API for KeePass Password Databases - Read/Write 2.x (File versions 3 and 4), Read 1.x
Apache License 2.0
251 stars 70 forks source link

Database allows to create properties with the same name #54

Closed giusvale-dev closed 1 year ago

giusvale-dev commented 1 year ago
public static void main( String[] args )
    {
        try {

            Database database = new JacksonDatabase();
            Group test = database.newGroup("TEST");
            Entry entry = database.newEntry("Entry");

            entry.setTitle("Entry title");
            entry.setPassword("password");
            entry.setNotes("Notes");
            entry.setProperty("Properties 1", "Secret 1");
            entry.setProperty("Properties 1", "Secret 2");
            entry.setUsername("username");
            entry.setUrl("url");
            test.addEntry(entry);
            database.setName("My first DB");
            database.getRootGroup().addGroup(test);

            try (FileOutputStream outputStream = new FileOutputStream("test.kdbx")) {
                database.save(new KdbxCreds("123".getBytes()), outputStream);
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

I expected an exception (we can't have 2 properties with the same name) but the result is the property overwritten. This is an expected result?

jorabin commented 1 year ago

yes, expected, how would you overwrite a property otherwise?

giusvale-dev commented 1 year ago

👌