/// <summary>
        /// Changes user password
        /// </summary>
        /// <param name="id">User Id</param>
        /// <param name="currentPassword">CurrentPassword</param>
        /// <param name="newPassword">Newpassword</param>
        /// <param name="remarks">List of erros</param>
        /// <returns>If the operation succeded</returns>
        public async Task <bool> ChangePassword(Guid id, string currentPassword, string newPassword, Dictionary <string, string> remarks)
        {
            var userModel = await _UserDb.GetSingle(id);

            if (userModel == null || !ValidatePassword(userModel, currentPassword))
            {
                remarks.Add("UserDoesntExistsOrInvalidPws", "User doesn't exists or the password is invalid");
                return(false);
            }

            var now = DateTime.Now;
            UserPasswordHistory userPassword = new UserPasswordHistory
            {
                Id          = Guid.NewGuid(),
                InitialDate = now,
                Password    = EncriptionHelper.EncriptPassword(newPassword, now)
            };

            if (userModel.PasswordHistory == null)
            {
                userModel.PasswordHistory = new List <UserPasswordHistory> {
                    userPassword
                }
            }
            ;
            else
            {
                userModel.PasswordHistory.Add(userPassword);
            }
            return(await _UserDb.Update(userModel));
        }
        private bool ValidatePassword(UserModel userModel, string password)
        {
            if (userModel.PasswordHistory == null || userModel.PasswordHistory.Count == 0)
            {
                return(true);
            }
            var lastPassword = userModel.PasswordHistory.OrderByDescending(x => x.InitialDate).First();
            var convertedPwd = EncriptionHelper.EncriptPassword(password, lastPassword.InitialDate);

            return(lastPassword.Password.SequenceEqual(convertedPwd));
        }
        private static void CheckEncryption(RegistryHelper registryHelper)
        {
            var HistoricConnectionStrings = registryHelper.GetSubKeys(SavedConnectionKey);

            // Do the encrption if the strings were not encrypted already.

            foreach (var x in HistoricConnectionStrings)
            {
                if (x.Value.Contains("Data"))
                {
                    RegistryHelper helper = new RegistryHelper();
                    if (!string.IsNullOrEmpty(x.Key))
                    {
                        helper.Delete(ConnectionHelper.SavedConnectionKey, x.Key);
                    }
                    helper.Write(ConnectionHelper.SavedConnectionKey, x.Key,
                                 EncriptionHelper.EncryptString(x.Value, ConnectionHelper.Salt));
                }
            }
        }
Exemplo n.º 4
0
 private void btnSave_Click(object sender, System.EventArgs e)
 {
     if (dxValidationProvider1.Validate())
     {
         RegistryHelper helper = new RegistryHelper();
         if (!string.IsNullOrEmpty(previousKeyName))
         {
             helper.Delete(ConnectionHelper.SavedConnectionKey, previousKeyName);
         }
         helper.Write(ConnectionHelper.SavedConnectionKey, connectionString.Name, EncriptionHelper.EncryptString(connectionString.ToString(), "hcmis-warehouse"));
         connectionString.SaveAsDefault();
         XtraMessageBox.Show("Your changes have been saved");
         Caller.Show();
         ((ConnectionChoices)Caller).RefreshConnectionList();
         this.Close();
     }
 }