How to create customised user identifier?

Hi guys, is it possible to create an unique auto-incremented identifier field for a user?

For example,

CUST2001
CUST2002
CUST2003

The use case is to display this identifier on invoices instead of using UUID

Just curious, why username isn’t enough?

Email is used as username in this case.

  1. Privacy Concerns
  • Displaying email addresses on invoices might expose sensitive customer information, especially if the invoice is shared or intercepted.
  1. Length and Complexity
  • Email addresses vary in length and format, making them less readable than simpler reference IDs. For example: john.doe@example.com is much harder to convey over the phone than ‘INV-12345’.
  1. Not a True Identifier
  • Emails can change (e.g., if a customer updates their contact info), leading to issues with traceability or confusion when referencing past invoices.
  1. Risk of Misuse
  • Including email addresses prominently may make them targets for spam or phishing attacks if invoices are shared externally.

I’d add a custom attribute in “Realm settings” (there is a section “User profile”).

Then it depends.

If you have capability to add service provider into your Keycloak deployment:
You can implement event listener SPI according to the doc: Server Developer Guide that will fill this field correctly. Existing users I believe may be prefilled directly in the db.

If you don’t have capability to add service provider to your deployment of KC. Just use API to do it, but it will be certanly less sync, so you need to poll to get all new users or wait for them to authenticate into a relying party (final software users authenticate into) that you have access to the code base or plugining.
The doc is here: API Documentation

Thank you for your advice.