Search This Blog

10 July 2011

Authenticating a user with user-name and password against Windows with X++

The AccountManagement Namespace was introduced with .Net 3.5 and provides some very useful classes which are, by referencing this assembly, available with X++, as well. At least if you've installed .Net 3.5.

Here's an example how to authenticate a username and password against Windows with the PrincipalContext class and the ValidateCredentials-method.
boolean isAuthenticated = false;
System.DirectoryServices.AccountManagement.PrincipalContext principalContext;

principalContext = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType::Domain, "");
isAuthenticated = principalContext.ValidateCredentials("username", "password");

if (isAuthenticated)
    //do something
    //do something

Update: (15/07/11) And bcause of the Google search keywords: The username and password for the VPC are Administrator and Passw0rd (or pass@word1 depends on the vpc) ... ;-)

No comments:

Post a Comment