Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Changing user passwords

Changing user passwords

Scheduled Pinned Locked Moved C / C++ / MFC
windows-admintoolsregexhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Frank Deo
    wrote on last edited by
    #1

    Would someone help me by telling me why this doesnt work? I'm trying to write an easy way for me and my co-admins to change users passwords w/o using the standard tools. Note, that the DC= parts reflect my current Active Directory DC on my test machine. I know for a fact that the user I am requesting is at CN=UserName,CN=Users,DC=HOME,DC=Local.

    void CChangePWDDlg::OnChangepw()
    {
    CString sUID, sPassword, sPWConfirm;
    GetDlgItemText(IDC_USERID, sUID);
    GetDlgItemText(IDC_PASSWORD, sPassword);
    GetDlgItemText(IDC_PWCONFIRM, sPWConfirm);

    if (sUID.GetLength() == 0) 
    {
    	AfxMessageBox("User ID cannot be empty");
    	return;
    }
    
    if (sPassword.GetLength() == 0) 
    {
    	AfxMessageBox("Password cannot be empty");
    	return;
    }
    
    if (sPWConfirm.GetLength() == 0) 
    {
    	AfxMessageBox("Re-Enter Password");
    	return;
    }
    
    if (strcmp(sPassword, sPWConfirm) != 0)
    	AfxMessageBox("Passwords Don't Match");
    else
    {
    	CString objPath = "LDAP://CN=";
    	objPath = objPath += sUID;
    	objPath = objPath += ",CN=Users,DC=HOME,DC=Local";
    	
    	BSTR oPath = objPath.AllocSysString();
    	IADsUser \*pUser;
    	HRESULT h2;
    	h2 = ADsGetObject(oPath, IID\_IADsUser, (void\*\*) &pUser);
    	
    	if (FAILED(h2))
    	{
    		AfxMessageBox("Failed to get user");
    		SysFreeString(oPath);
    		pUser->Release();
    		return;
    	}
    	else
    	{
    		SysFreeString(oPath);
    		
    		BSTR oPass = sPassword.AllocSysString();
    
    		HRESULT hr;
    		hr = pUser->SetPassword(oPass);
    		pUser->Release();
    
    		if (FAILED(hr)) 
    		{
    			AfxMessageBox("Failed to set password");
    			return;
    		}
    		else
    		{
    			SetDlgItemText(IDC\_USERID, "");
    			SetDlgItemText(IDC\_PASSWORD, "");
    			SetDlgItemText(IDC\_PWCONFIRM, "");
    		}
    	}
    	
        }
    

    }

    I always receive "Failed to get user". Thanks, Frank PS. Alot of this code was used from examples on MSDN. :-O

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups