Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts

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!






Wednesday, August 22, 2012

Update Windows Local Account Password

I would like to enable users to update their account passwords through a Web Part in SharePoint 2010.

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

string userPath = "WinNT://computerName/userName";
DirectoryEntry userEntry = new DirectoryEntry(userPath);
object[] password = {newPassword};
object ret = userEntry.Invoke("SetPassword", password);
userEntry.CommitChanges();

userEntry.Close();

Above snippet code can really update their passwords!

Change local administrator password in C#