Wednesday, September 5, 2012

Verify Local Windows Account Password

I would like to verify local windows account and password through a web part in SharePoint 2010. The code snippet is show below:

protected bool verifyUserAccount(string computerName, string userName, string password)
{
    bool flag = false;
    using (PrincipalContext context = new PrincipalContext(ContextType.Machine, computerName, userName, password))
    {
        flag = context.ValidateCredentials(userName, password);
    }
    return flag;
}

Then the above snippet can really verify local windows account and password!






No comments:

Post a Comment