首页 > 解决方案 > 表格中发送后看到的数据,会是什么?

问题描述

数据是在表单中发送后看到的,可能是我使用angular作为前端,nodejs作为后端,非常感谢支持,需要注意的是我是angular初学者

<div class="container p-5">
  <div class="row">
    <div class="col-md-4 mx-auto">
      <div class="card">
        <div class="card-header">
          Acceso al Sistema
        </div>
        <div class="card-body">
          <form (submit)="login()" >
            <div class="form-group">
              <input type="text"  [(ngModel)]="user.email" name="email" class="form-control" placeholder="Email" autofocus>
            </div>
            <div class="form-group">
              <input type="password" [(ngModel)]="user.contrasenia" name="password" class="form-control" placeholder="Contraseña" >
            </div>
            <button type="submit" class="btn btn-primary btn-block">
              Ingresar
            </button>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>

export class Usuarios {

  constructor(email=''){
    this.email = email
  }
  _id:string;
  nombre_completo: string;
  apellido_paterno:string;
  apellido_materno:string;
  roles:string;
  email:string;
  contrasenia:string;

}

在此处输入图像描述

标签: node.jsangular

解决方案


您可以加密数据并发送到服务器,在服务器端您可以解密数据请在下面找到示例代码

import * as CryptoJS from 'crypto-js';




  decryptParams(result, password) {
    // console.log('to decrypt' + result);
    let decryptedString: any;
    const words = CryptoJS.enc.Base64.parse(result);
    // console.log('to decrypt' + words);
    const textString = CryptoJS.enc.Utf8.stringify(words);
    decryptedString = CryptoJS.AES.decrypt(textString, password);
    decryptedString = this.hex2a(decryptedString);
    return JSON.parse(decryptedString);
  }


  encryptParams(params, password) {
    let encryptedParams: any;
    encryptedParams = CryptoJS.AES.encrypt(JSON.stringify(params), password);
    encryptedParams = CryptoJS.enc.Utf8.parse(encryptedParams);
    encryptedParams = CryptoJS.enc.Base64.stringify(encryptedParams);
    // console.log('encry' + encryptedParams);
    return encryptedParams;
  }


 hex2a(hexx) {
    const hex = hexx.toString(); // force conversion
    let str = '';
    for (let i = 0; i < hex.length; i += 2) {
      str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));

    }
    return str;
  }

推荐阅读