FreeOTPPlus icon indicating copy to clipboard operation
FreeOTPPlus copied to clipboard

[Bug] Import does *not* overwrite all existing tokens

Open lemmy04 opened this issue 3 years ago • 7 comments

I just imported a backup from my tablet onto my phone, and contrary to the warning it did not overwrite the existing tokens - it added the new ones at the end of the list, creating loads of duplicates, possible bad ones too if the token had been recreated since the last import.

lemmy04 avatar Jun 14 '22 19:06 lemmy04

Which format of backup are you using? I think the Json format should overwrite but not other formats.

helloworld1 avatar Jun 14 '22 20:06 helloworld1

I tried with both, both appended instead of overwriting.

lemmy04 avatar Jun 14 '22 20:06 lemmy04

Got it. This sounds like a behavior change by a change that allows the account with same issuer / account combo to be added. See https://github.com/helloworld1/FreeOTPPlus/issues/15

helloworld1 avatar Jun 14 '22 23:06 helloworld1

How about when importing Tokens via JSON we could check for every imported Token if there already is a Token in the DB that has the same issuer, label and secret combination. If yes, we overwrite the existing Token by keeping its internal id and using all other fields from the imported Token, if not, the new Token is inserted as usual. This would allow multiple Tokens for the same issuer + account (label) but would detect and overwrite actual duplicates when importing.

PhilKes avatar Jul 12 '22 17:07 PhilKes

Yea, I think that's a reasonable way to deduplicate the token.

helloworld1 avatar Jul 13 '22 05:07 helloworld1

here's a fun bit: this weekend I tried again to copy my freeotp+ tokens from one device to the other, so i exported as json and imported on the other device, and this time around it did overwrite the existing tokens just fine o.0

lemmy04 avatar Jul 13 '22 06:07 lemmy04

@lemmy04 Thats probably due to the fact that when importing, the id (primary-key) is set to the index of the token in the JSON Token list. Therefore if you import a JSON once and then again, the second time all the same tokens will also have the same id and therefore will be correctly overwritten.

PhilKes avatar Jul 13 '22 10:07 PhilKes