Beispiel #1
0
        public void Create(int employeeId, string userName, bool isDisabled, IEnumerable <int> roleIds)
        {
            SettingsService    settingsService    = new SettingsService(Name);
            MembershipSettings membershipSettings = settingsService.GetMembershipSettings();
            string             password           = settingsService.GetInitialPasswordSettings().InitialPassword;
            string             encryptedPassword  = PasswordSecurity.EncryptPassword(membershipSettings, password, out int crypto, out string key, out string iv);

            XElement xUser = new XElement("User");

            xUser.SetElementValue("EmployeeId", employeeId);
            xUser.SetElementValue("UserName", userName);
            xUser.SetElementValue("LoweredUserName", userName.ToLower());
            xUser.SetElementValue("IsDisabled", isDisabled);
            xUser.SetElementValue("Password", encryptedPassword);
            xUser.SetElementValue("PasswordCrypto", crypto);
            xUser.SetElementValue("PasswordKey", key);
            xUser.SetElementValue("PasswordIV", iv);

            XElement xRoles = new XElement("Roles");

            foreach (int roleId in roleIds)
            {
                XElement xRole = new XElement("Role");
                xRole.SetElementValue("Id", roleId);
                xRoles.Add(xRole);
            }

            if (xRoles.HasElements)
            {
                xUser.Add(xRoles);
            }

            Modifier.Create(xUser);
        }
Beispiel #2
0
        public void ResetPassword(int id, string password)
        {
            string userName = GetUserName(id);

            MembershipSettings membershipSettings = new SettingsService(Name).GetMembershipSettings();
            string             encryptedPassword  = PasswordSecurity.EncryptPassword(membershipSettings, password, out int crypto, out string key, out string iv);

            XElement xUser = new XElement("User");

            xUser.SetElementValue("Id", id);
            xUser.SetElementValue("Password", encryptedPassword);
            xUser.SetElementValue("PasswordCrypto", crypto);
            xUser.SetElementValue("PasswordKey", key);
            xUser.SetElementValue("PasswordIV", iv);

            XElement xSecurityEntry = ThreadDataStore.RequestInfo.CreateSecurityEntry(ODataQuerier);

            xSecurityEntry.SetElementValue("Operation", "ResetPassword");
            xSecurityEntry.SetElementValue("Contents", string.Format("UserId:{0},UserName:{1}", id, userName));
            xSecurityEntry.SetElementValue("UserId", id);

            Update(xUser, xSecurityEntry);
        }