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, "contoso.com");
isAuthenticated = principalContext.ValidateCredentials("username", "password");
principalContext.Dispose();

if (isAuthenticated)
{
    //do something
}
else
{
    //do something
}

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

1 comment:

  1. This is a really helpful guide for anyone looking to sign up for Twitter without using their personal phone number! Using a service like PVApins to get a virtual number, especially from Brazil, seems like a great way to protect privacy and avoid unwanted data collection. The step-by-step process is clear and easy to follow, and it's good to know there are secure alternatives out there for registering on platforms like Twitter. Definitely worth considering for those concerned about their online privacy!
    Visit us:- https://pvapins.com/?/EN

    ReplyDelete