<commit_before>import { SHA3 } from 'crypto-js';

function buildPassword(password, domain) {
  return SHA3(password, domain).toString().substr(0, 10);
}

const password = (state = { result: '', password: '', domain: '' }, action) => {

  let saltedPassword = '';

  switch (action.type) {

    case 'UPDATE_PASSWORD':

      // Apply password transformation
      if (action.value) {
        saltedPassword = buildPassword(action.value, state.domain);
      }

      return { ...state, result: saltedPassword, password: action.value };
      // return Object.assign({}, state, { result: saltedPassword, password: action.value });

    case 'UPDATE_DOMAIN':
<commit_msg>Hashing the password and salting with domain, adding number and special char<commit_after>import { SHA3 } from 'crypto-js';
import base64 from 'base-64';

function buildPassword(password, domain) {

  if (!password || !domain) return '';

  let new_password = base64.encode(SHA3(password + domain).toString()).substr(0, 10);

  // We need to have at least a number in my super password
  // So we take charcode of first and last new_password character and after first,

  let charCode = new_password.charCodeAt(Math.ceil(new_password.length / 2));

  new_password += charCode;

  // and one of this special chars ^!@# adding the end
  new_password = '^' + new_password;

  return new_password;
}

const password = (state = { result: '', password: '', domain: 'facebook.com' }, action) => {

  let saltedPassword = '';

  switch (action.type) {

    case 'UPDATE_PASSWORD':

      // Apply password transformation
      if (action.value) {
        saltedPassword = buildPassword(action.value, state.domain);
      }

      return { ...state, result: saltedPassword, password: action.value };
      // return Object.assign({}, state, { result: saltedPassword, password: action.value });

    case 'UPDATE_DOMAIN':

{'fraction_non_alphanumeric': 0.1339712918660287, 'fraction_numerical': 0.009037745879851143, 'mean_word_length': 3.556900726392252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4121805', 'n_tokens_mistral': 558, 'n_tokens_neox': 529, 'n_words': 159}