David Ryan

David Ryan

  • NA
  • 2
  • 843

Pass Smartcard Credentials to DirectoryServices

Nov 21 2017 6:59 PM

I'm wondering if it is possible to store smartcard credentials in an application and then pass them to items such as a password reset using DirectoryServices.AccountManagement. 

  1. PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "abc.com:3268""DC=abc, DC=com", Username, Password);  
  2.   
  3.             UserPrincipal user = UserPrincipal.FindByIdentity(domainContext, "myUser");  
  4.   
  5.             user.VoiceTelephoneNumber = "123-456-7890";  
  6.             user.Save();  

 In the above example I want to be able to use a smartcard (I have a class that uses the System.Security.Cryptography.X509Certificates namespace) to run the phone number reset code.  I am able to get the credentials through the X509Certificates, and am able to run an executable using the credential Username and Password - but I do not want to start the application with those credentials.  I just want to be able to store the credentials so only when certain features are used (resets, unlocks, etc) it access the credentials.  Is this possible?