I need to verify user credentials from an external service, so I use authentication VirtualUser.
BuildVirtualUserby checking the roles for him, saving the user profile, and then log in with that name.
I ran into the problem that every day when I log in, with the same credentials, Sitecore creates a new user in the experience profile.
What do I need to change in my code to make sure that when I log in to the virtual user, Sitecore gets the old user profile?
I was thinking of creating a user in sitecore with the same shared password. Instead of using virtual user and authentication directly with sitecore. It is right?
Here is my code:
Sitecore.Security.Accounts.User user = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(sitecoreUser, true);
string roleName = @"newRole\User";
Sitecore.Security.Accounts.Role demoRole = Sitecore.Security.Accounts.Role.FromName(roleName);
if (Sitecore.Security.Accounts.Role.Exists(roleName) && !demoRole.IsMember(user, true, false))
{
user.Roles.Add(Sitecore.Security.Accounts.Role.FromName(roleName));
}
user.Profile.Name = name;
user.Profile.Email = email;
user.Profile.FullName = fullname;
user.Profile.Save();
Sitecore.Security.Authentication.AuthenticationManager.Login(user.Name);
Tracker.Initialize();