If public signup is enabled, it's likely to have multiple usernames for the same user. To merge their data, you could run sql to change usernames, but you cant merge usernames on the users table because you'll get a duplicate key violation. Therefore you'd need a script to detect an existing username, query the duplicates group associations, associate the duplicate's groups to the primary's user ID, and then remove the duplicate.
This is different from a request to match internal with external user IDs, http://jira.atlassian.com/browse/CONF-10654 .
Note that implementing this will also have to take into account what to do with existing user content, mentions of affected users, and their user settings (including profile picture, preferred language, timezone, notification configuration and watches).