Exemple #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);
        }
Exemple #2
0
        protected static bool ComparePassword(XElement user, string password)
        {
            string encryptedPassword = user.Element("Password").Value;
            int    crypto            = int.Parse(user.Element("PasswordCrypto").Value);
            string key = user.Element("PasswordKey").Value;
            string iv  = user.Element("PasswordIV").Value;

            return(PasswordSecurity.ComparePassword(encryptedPassword, crypto, key, iv, password));
        }
Exemple #3
0
        public void ChangePassword(string password, string newPassword)
        {
            XElement xSecurityEntry = ThreadDataStore.RequestInfo.CreateSecurityEntry(ODataQuerier);

            xSecurityEntry.SetElementValue("Operation", "ChangePassword");

            SettingsService    settingsService    = new SettingsService(Name);
            MembershipSettings membershipSettings = settingsService.GetMembershipSettings();

            if (!PasswordSecurity.ValidatePassword(membershipSettings, newPassword, out string[] errorMessages))
Exemple #4
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);
        }