in LinuxCommunicator/Credentials.cs [648:711]
internal static string ToUniqueLocalAccount(string domainAccount)
{
if (string.IsNullOrWhiteSpace(domainAccount))
{
throw new ArgumentNullException("domainAccount");
}
string uniqueLocalAccount;
if (domainAccount.StartsWith("NT AUTHORITY\\"))
{
uniqueLocalAccount = domainAccount;
}
else
{
// unique local account = Purged local name + suffix (hash code of domain account)
string localname = Credentials.ToLocalAccount(domainAccount);
// Remove all delimiters from the source
string purged = RemoveChars(localname, delimiters);
// We only take the first MaxPrefixLength characters from
// the seed user name so as to guarantee at least
// MaxPrefixLength characters from the hash.
if (purged.Length > MaxPrefixLength)
{
purged = purged.Substring(0, MaxPrefixLength);
}
// The length is 10 or larger
int suffixLength = MaxAccountNameLength - purged.Length;
var builder = new StringBuilder();
builder.Append(purged);
using (SHA256 sha256 = SHA256.Create())
{
string suffix = localname;
int retry = 0;
do
{
sha256.ComputeHash(Encoding.Default.GetBytes(suffix));
byte[] hash = sha256.Hash;
suffix = RemoveChars(Convert.ToBase64String(hash), invalidBase64UserNameChars);
retry++;
if (retry > MaxHashRetryCount)
{
throw new ApplicationException(
"Failed to create a hash suffix to create a user name after maximum retries.");
}
}
while (suffix.Length < suffixLength);
builder.Append(suffix.Substring(0, suffixLength));
}
uniqueLocalAccount = builder.ToString();
}
return uniqueLocalAccount;
}