We allow our users to enter Active Directory account information using either an NT account name (domain\account) or a UPN (account@email,xxx). I would like to write some code to validate the account in active directory before allowing the user to move on. Note, we are not validating a password, just the account name.
I can use UserPrincipal.FindByIdentity, however, this expects only a user name.
Can I validate the account name in either format using .NET? Or am I relegated to parsing out out the domain from the account name to validate both parts of the user input? The later would be a bit messy, woudln’t it?
Attempt to create a WindowsIdentity from the UPN:
It will succeed for an UPN valid in AD, throw an exception for invalid ones. The process validating the UPN must be connected to the AD and have proper access rights (ie. no anonimization due to delegation constraint on an impersonated context).