public bool ResetPassword(common.clsUser User, common.clsPassword Password) { try { // Get the full LDAP path to the user // Set the DirectoryEntry object for this User DirectoryEntry de = clsADMngr.GetUserByLoginID(User.LoginID); string strLDAPPath = de.Properties["distinguishedName"].Value.ToString(); // Instantiate a new PBSAD object using this user path clsADMngr = new ad.clsActiveDirectoryManager(CONFIG_ADSI_AdminUsr, CONFIG_ADSI_AdminPwd, strLDAPPath); // Return success/failure; bool boolSuccess = clsADMngr.ResetPassword(User, Password); if (boolSuccess) { strMessage += "Password change successful<br>"; return(true); } else { throw new System.Exception(); } } catch (System.Exception ex) { strMessage += "Password change failed!<br><br>" + ex.GetBaseException().Message + "<br>"; clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to ResetPassword!", ex); } return(false); }
public bool ResetPassword(common.clsUser User, common.clsPassword Password) { try { this.strLDAPPath = this.GetUserByLoginID(User.LoginID).Path.Replace("LDAP://", CONFIG_ADSI_Root + "/"); // Add NewPassword to an array string strNewPwd = Password.NewPassword; object[] arrPwd = new object[1]; arrPwd.SetValue(strNewPwd, 0); // Get the DirectoryEntry for this User, authenticating with the Admin usr/pwd de = new DirectoryEntry(strLDAPPath, strAdminUsr, strAdminPwd); // Call native AD method to set new Password de.Invoke("setPassword", arrPwd); de.CommitChanges(); de.RefreshCache(); return(true); } catch (System.Exception ex) { clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to ResetPassword! " + strLDAPPath + " ", ex); return(false); } }
public bool DeleteADAccount(common.clsUser User, common.clsPassword Password) { // Get the DirectoryEntry for the supplied MemberStation OU strLDAPPath += "/OU=" + User.Profile.Organization + ",OU=MemberStations," + strLDAPLocalDomain; try { de = new DirectoryEntry(strLDAPPath, strAdminUsr, strAdminPwd); // Get the DirectoryEntry for this User DirectorySearcher srch = new DirectorySearcher(strLDAPPath); srch.Filter = "(samAccountName=" + User.LoginID + ")"; srch.PropertiesToLoad.Add("CN"); SearchResult srchResult = srch.FindOne(); DirectoryEntry deUser = srchResult.GetDirectoryEntry(); // Remove this User from OU container de.Children.Remove(deUser); deUser.Dispose(); srch.Dispose(); de.CommitChanges(); de.RefreshCache(); return(true); } catch (System.Exception ex) { clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to DeleteADAccount! " + strLDAPPath + " ", ex); return(false); } }
public common.clsUser Update(common.clsUser User, common.clsPassword Password) { try { bool boolSuccess = false; // User opted to ChangePassword if (Password.OldPassword != null && Password.NewPassword != null) { boolSuccess = this.ChangePassword(User, Password); if (!boolSuccess) { throw new System.Exception("Password change failed"); } // strMessage } // Admin opted to ResetPassword else if (Password.NewPassword != null && Password.Hint != null) { boolSuccess = this.ResetPassword(User, Password); if (!boolSuccess) { throw new System.Exception("Password reset failed"); } // strMessage } // Update Active Directory and StationContact records if (User.Profile.Organization.ToUpper() != "PBS") { boolSuccess = clsADMngr.UpdateADAccount(User, Password); if (!boolSuccess) { throw new System.Exception("Account update to Active Directory failed!"); } } boolSuccess = clsStationDBMngr.UpdateProfile(User, Password); if (!boolSuccess) { throw new System.Exception("Account update to Stations DB failed!"); } clsUser = clsStationDBMngr.GetUser(User.LoginID); // Update WebBoard account clsWebBoardMngr.wbUpdateUser(clsUser); strMessage += "Account update for \"" + User.DisplayName + "\" succeeded<br>"; return(clsUser); } catch (System.Exception ex) { if (strMessage.Length == 0) { strMessage = "Account update failed!"; } clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to Update account!", ex); throw new System.Exception(strMessage); } }
public common.clsUser ApproveRegistration(common.clsUser User, common.clsPassword Password, common.clsRequest Request) { try { // Create Active Directory and StationContact records bool boolSuccess = false; boolSuccess = clsADMngr.CreateADAccount(User, Password); if (!boolSuccess) { throw new System.Exception("Failed to create new Active Directory account!"); } boolSuccess = clsStationDBMngr.ApproveRegistrationRequest(Request); if (!boolSuccess) { throw new System.Exception("Failed to insert STATIONS.tblREGISTRATIONREQUESTS record into STATIONS.tblSTATIONCONTACTS!"); } clsUser = clsStationDBMngr.GetUser(Request.UserInfo.LoginID); // Create new WebBoard account try { clsWebBoardMngr.wbAddUser(clsUser, CONFIG_CONN_WebBoardDefaultBoardID); if (clsWebBoardMngr.wbGetWebBoardIdForUser(clsUser) <= 0) { throw new System.Exception("Failed to create new WebBoard account!"); } } catch (System.Exception ex) { clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessWebBoardDBManager", "Unable to wbAddUser!", ex); throw new System.Exception(ex.GetBaseException().Message); } strMessage += "Registration Request from \"" + Request.UserInfo.FirstName + " " + Request.UserInfo.LastName + "\" has been approved"; return(clsUser); } catch (System.Exception ex) { strMessage += ex.GetBaseException().Message; clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to ApproveRegistration!", ex); } return(User); }
public common.clsUser Delete(common.clsUser User, common.clsPassword Password) { try { // Delete WebBoard account try { clsWebBoardMngr.wbDeleteUser(User); } catch (System.Exception ex) { clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessWebBoardDBManager", "Unable to wbDeleteUser!", ex); throw new System.Exception(ex.GetBaseException().Message); } // Delete Active Directory and StationContact records bool boolSuccess = false; boolSuccess = clsADMngr.DeleteADAccount(User, Password); if (!boolSuccess) { throw new System.Exception(); } boolSuccess = clsStationDBMngr.DeleteProfile(User, Password); if (!boolSuccess) { throw new System.Exception(); } strMessage += "Account deletion for \"" + User.DisplayName + "\" succeeded<br>"; return(User); } catch (System.Exception ex) { strMessage += "Account deletion failed!<ul><li>" + ex.GetBaseException().Message + "<br><br>" + ex.GetBaseException().StackTrace + "</li></ul>"; clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to Delete account!", ex); } return(User); }
public bool CreateADAccount(common.clsUser User, common.clsPassword Password) { this.strLDAPPath += "/OU=" + User.Profile.Organization + ",OU=MemberStations," + strLDAPLocalDomain; DirectoryEntry deGroupOU = this.GetUserByLoginID(User.Profile.Organization + "Usr"); DirectoryEntry deGroupPBSCUsers = this.GetUserByLoginID("PBSC All Users"); // Add User to OU=[MemberStation] // Set User account properties // Set User account password // Set User account = Enabled // Add User to [MemberStation]Usr Group (Use the pre-W2K AD group name!!!!!!!!!) // Add User to "PBSC All Users" Group bool boolSuccess = false; boolSuccess = this.AddToOU(User, strLDAPPath); if (!boolSuccess) { return(false); } boolSuccess = this.UpdateADAccount(User, Password); if (!boolSuccess) { return(false); } boolSuccess = this.ResetPassword(User, Password); if (!boolSuccess) { return(false); } boolSuccess = this.EnableADAccount(User); if (!boolSuccess) { return(false); } boolSuccess = this.AddUserToGroup(User, deGroupOU.Path); if (!boolSuccess) { return(false); } // boolSuccess = this.AddUserToGroup(User, deGroupPBSCUsers.Path); if (!boolSuccess) { return false; } deGroupOU.Dispose(); deGroupPBSCUsers.Dispose(); return(boolSuccess); }
public common.clsUser Create(common.clsUser User, common.clsPassword Password) { try { // Create Active Directory and StationContact records bool boolSuccess = false; boolSuccess = clsADMngr.CreateADAccount(User, Password); boolSuccess = clsStationDBMngr.CreateProfile(User, Password); if (!boolSuccess) { throw new System.Exception("Failed to insert STATIONS.tblSTATIONCONTACTS record!"); } clsUser = clsStationDBMngr.GetUser(User.LoginID); // Create new WebBoard account try { clsWebBoardMngr.wbAddUser(clsUser, CONFIG_CONN_WebBoardDefaultBoardID); } catch (System.Exception ex) { clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessWebBoardDBManager", "Unable to wbAddUser!", ex); throw new System.Exception(ex.GetBaseException().Message); } strMessage += "Account creation for \"" + User.DisplayName + "\" succeeded<br>"; return(clsUser); } catch (System.Exception ex) { strMessage += "Account creation failed!<ul><li>" + ex.GetBaseException().Message + "<br><br>" + ex.GetBaseException().StackTrace + "</li></ul>"; clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessAccountManager", "Unable to Create account!", ex); } return(User); }
/// <summary>This method resets a User's password. Calls native AD "setPassword" method</summary> /// <param name="User">The User to be reset</param> /// <param name="Password">The Password object containing NewPassword</param> /// <returns>bool</returns> public bool ResetPassword(common.clsUser User, common.clsPassword Password) { return(_clsPBSActiveDirectory.ResetPassword(User, Password)); }
/// <summary> /// This method deletes an account /// </summary> /// <param name="User">The User to delete</param> /// <param name="Password">Not used</param> /// <returns>bool</returns> public bool DeleteADAccount(common.clsUser User, common.clsPassword Password) { return(_clsPBSActiveDirectory.DeleteADAccount(User, Password)); }
public bool UpdateADAccount(common.clsUser User, common.clsPassword Password) { try { de = this.GetUserByLoginID(User.LoginID); // Update the DirectoryEntry property collection for this User de.Properties["samAccountName"].Value = User.LoginID; de.Properties["userPrincipalName"].Value = User.LoginID + "@" + ConfigurationSettings.AppSettings["ActiveDirectoryRootString"].Replace("LDAP://", ""); de.Properties["givenName"].Value = User.Profile.FirstName; de.Properties["sn"].Value = User.Profile.LastName; de.Properties["displayName"].Value = User.DisplayName; //string strInitials = User.Profile.FirstName.Substring(0,1); //if (!common.clsFunctions.IsFieldEmpty(User.Profile.MiddleName)) { strInitials += User.Profile.MiddleName.Substring(0,1); } //strInitials += User.Profile.LastName.Substring(0,1); //de.Properties["initials"].Value = strInitials; de.Properties["company"].Value = User.Profile.Organization; // de.Properties["title"].Value = User.Profile.Title; // de.Properties["description"].Value = User.Profile.JobFunction; // de.Properties["streetAddress"].Value = User.Profile.Address1 + ", " + User.Profile.Address2; // de.Properties["l"].Value = User.Profile.City; // de.Properties["st"].Value = User.Profile.State; // de.Properties["postalCode"].Value = User.Profile.Zip; // de.Properties["c"].Value = "US"; // de.Properties["co"].Value = "UNITED STATES"; // de.Properties["countryCode"].Value = 840; /* * string strTelephone = ""; * * bool boolExtExists = true; * if (User.Profile.Extension == null) { boolExtExists = false; } * if (User.Profile.Extension.Length.Equals(0)) { boolExtExists = false; } * * if (boolExtExists) * { * strTelephone = User.Profile.AreaCode + " " + User.Profile.Exchange + " ext. " + User.Profile.Extension; * } * else * { * strTelephone = User.Profile.AreaCode + " " + User.Profile.Exchange; * } * de.Properties["telephoneNumber"].Value = strTelephone; * de.Properties["facsimileTelephoneNumber"].Value = User.Profile.FaxAreaCode + " " + User.Profile.FaxExchange; */ de.Properties["mail"].Value = User.Profile.EmailAddress; /* * CDOEXM.IMailRecipient mailUser = (CDOEXM.IMailRecipient) de.NativeObject; * try { mailUser.MailDisable(); } * catch { } * mailUser.MailEnable( "SMTP:" + User.Profile.EmailAddress ); */ /* * if (de.Properties.Contains("proxyAddresses")) * { * de.Properties["proxyAddresses"].Clear(); * de.Properties["proxyAddresses"].Add( "SMTP:"+User.Profile.EmailAddress ); * de.Properties["proxyAddresses"].Add( "X400:c=us;a= ;p=company US;o=Exchange;s="+User.Profile.LastName+";g="+User.DisplayName+";" ); * } * if (de.Properties.Contains("mailNickname")) * { * de.Properties["mailNickname"].Value = User.LoginID; * } * if (de.Properties.Contains("targetAddress")) * { * de.Properties["targetAddress"].Value = "SMTP:"+User.Profile.EmailAddress; * } */ // Commit changes, refresh cache de.CommitChanges(); de.RefreshCache(); return(true); } catch (System.Exception ex) { clsErr = new common.LogError(); clsErr.WriteLogEntry(common.LogError.LogEntryType.Error, "PBSConnectBusinessActiveDirectoryManager", "Unable to UpdateADAccount! " + strLDAPPath + " ", ex); return(false); } }