Changing user passwords
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
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