diff --git a/internal/user/repository/eventsourcing/eventstore.go b/internal/user/repository/eventsourcing/eventstore.go index 8ec07c1c71..962ffc9dcb 100644 --- a/internal/user/repository/eventsourcing/eventstore.go +++ b/internal/user/repository/eventsourcing/eventstore.go @@ -936,7 +936,11 @@ func (es *UserEventstore) AddOTP(ctx context.Context, userID string) (*usr_model if existing.IsOTPReady() { return nil, caos_errs.ThrowAlreadyExists(nil, "EVENT-do9se", "Errors.User.Mfa.Otp.AlreadyReady") } - key, err := totp.Generate(totp.GenerateOpts{Issuer: es.Multifactors.OTP.Issuer, AccountName: userID}) + accountName := existing.UserName + if existing.Email != nil { + accountName = existing.EmailAddress + } + key, err := totp.Generate(totp.GenerateOpts{Issuer: es.Multifactors.OTP.Issuer, AccountName: accountName}) if err != nil { return nil, err }