I assume you are talking about virtual users: https://doc.sitecore.com/xp/en/developers/92/sitecore-experience-manager/configure-federated-authentication.html#configure-virtual-and-persistent-users
I get the same result when I login with a virtual user. If the user does not exist a unique username is generated. This is done in the following class:
Sitecore.Owin.Authentication.Services.DefaultExternalUserBuilder.CreateUniqueUserName
This is what the decompiled class looks like for Sitecore 10.2:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Sitecore.Diagnostics;
using Sitecore.Owin.Authentication.Configuration;
using Sitecore.Owin.Authentication.Identity;
using Sitecore.SecurityModel.Cryptography;
using System;
using System.Text;
namespace Sitecore.Owin.Authentication.Services
{
public class DefaultExternalUserBuilder : ExternalUserBuilder
{
private readonly IHashEncryption _hashEncryption;
public DefaultExternalUserBuilder(ApplicationUserFactory applicationUserFactory, IHashEncryption hashEncryption)
{
Assert.ArgumentNotNull((object) applicationUserFactory, nameof (applicationUserFactory));
Assert.ArgumentNotNull((object) hashEncryption, nameof (hashEncryption));
this._hashEncryption = hashEncryption;
this.ApplicationUserFactory = applicationUserFactory;
}
public bool IsPersistentUser { get; set; }
protected ApplicationUserFactory ApplicationUserFactory { get; }
public override ApplicationUser BuildUser(UserManager<ApplicationUser> userManager, ExternalLoginInfo externalLoginInfo)
{
ApplicationUser user = this.ApplicationUserFactory.CreateUser(this.CreateUniqueUserName(userManager, externalLoginInfo));
user.IsVirtual = !this.IsPersistentUser;
user.Email = externalLoginInfo.Email;
return user;
}
protected virtual string CreateUniqueUserName(UserManager<ApplicationUser> userManager, ExternalLoginInfo externalLoginInfo)
{
Assert.ArgumentNotNull((object) userManager, nameof (userManager));
Assert.ArgumentNotNull((object) externalLoginInfo, nameof (externalLoginInfo));
IdentityProvider identityProvider = this.FederatedAuthenticationConfiguration.GetIdentityProvider(externalLoginInfo.ExternalIdentity);
if (identityProvider == null)
throw new InvalidOperationException("Unable to retrieve an identity provider for the given identity");
string domain = identityProvider.Domain;
string s = externalLoginInfo.Login.LoginProvider + externalLoginInfo.Login.ProviderKey;
string userName;
do
{
s += "$";
string str1 = System.Convert.ToBase64String(this._hashEncryption.ComputeHash(Encoding.ASCII.GetBytes(s))).Trim('=').Replace("/", string.Empty).Replace("+", string.Empty);
string str2 = str1.Substring(0, Math.Min(str1.Length, 10));
userName = domain + "\\" + str2;
}
while (userManager.FindByName<ApplicationUser, string>(userName) != null);
return userName;
}
}
}
As you can see the result of the CreateUniqueUserName
method will return the domain with the unique username. The username is also 10 characters long.
For example I got this username after login: extranet\ahLpHAJFUy
.
If you want to change this you can override the DefaultExternalUserBuilder
pipeline. If you search for Sitecore.Owin.Authentication.Services.DefaultExternalUserBuilder
in /sitecore/admin/showconfig.aspx
you should be able to find it. You can do a config transform to override it or change it manually in \App_Config\Sitecore\Owin.Authentication\Sitecore.Owin.Authentication.config
.
You can probably make a copy of the decompiled class I posted here and make your changes in that. So it should be possible to change it.