public void TestChangeAdministratorPassword() { SecurityAction securityAction = new SecurityAction(ConnectString); System.Console.WriteLine(securityAction.ChangeAdministratorPassword("Administrator", "Welcome-2015", "Welcome-2014")); }
Core.ServiceResponse ISecurityService.ChangeAdministratorPassword(SecurityServiceRequest securityServiceRequest) { if (string.IsNullOrEmpty(securityServiceRequest.Id) || string.IsNullOrEmpty(securityServiceRequest.Token) || string.IsNullOrEmpty(securityServiceRequest.Type)) { return new Core.ServiceResponse() { Code = 400, Message = "Id Type and Token should not null" }; } if (!securityServiceRequest.Type.Equals("Administrator") && !securityServiceRequest.Type.Equals("ProjectUser")) { return new Core.ServiceResponse() { Code = 400, Message = "Type should be Administrator or ProjectUser" }; } if (string.IsNullOrEmpty(securityServiceRequest.UserName) || string.IsNullOrEmpty(securityServiceRequest.CurrentPassword) || string.IsNullOrEmpty(securityServiceRequest.NewPassword)) { return new Core.ServiceResponse() { Code = 400, Message = "UserName CurrentPassword and NewPassword should not null" }; } string message = string.Empty; if (HP.TS.Devops.Security.SecurityCode.Success != HP.TS.Devops.Security.SecurityAction.CheckAccess(this.ConnectString, securityServiceRequest, out message)) { return new Core.ServiceResponse() { Code = 403, Message = securityServiceRequest.Id + " of type " + securityServiceRequest.Type + " have no access of " + message }; } SecurityAction securityAction = new SecurityAction(this.ConnectString); if (securityAction.ChangeAdministratorPassword(securityServiceRequest.UserName, securityServiceRequest.CurrentPassword, securityServiceRequest.NewPassword) <= 0) { return new Core.ServiceResponse() { Code = 500, Message = "Change Administrator Password Fail" }; } return new Core.ServiceResponse() { Code = 0, Message = "Success" }; }