You could use CB Invites to invite users and it'll generate them a code that can be used with the invite_code field provided with CB Invites. Simply set the field as required and it'd be needed for registration.
Alternative is to use CB Database Lookup fieldtype plugin and have a database of codes for it to compare against, you'd then have to manually give users codes.
To have it code based of subscription based simply create a Free plan then have your paid plans hide the code field (see workflows tab of your plans). This should give you the desired registration workflows either way.
As for the username generation this isn't really available. I mean you could disable the username field on registration then use CB Auto Actions to give the user a new username after registration trigger, but they won't see this until they register.