Payday rewrite, part 5

Step 6 of #2508. Follow-on from #2541.
That code is from 82b1012d5bffbc46a819c91ba69de37944941cd5 which fixes #1853. The correct solution would have been to modify all tables to replace usernames by participant IDs as foreign keys, but that's a big change, so I implemented a workaround instead.