首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在防火墙中存储散列密码

如何在防火墙中存储散列密码
EN

Stack Overflow用户
提问于 2020-04-07 22:47:18
回答 1查看 1.3K关注 0票数 0

所以我想要将一个用户对象保存在防火墙中,这是我第一次使用防火墙,所以我使用Bcrypt对密码进行编码,而不是将对象保存在防火墙中,但它似乎无法保存它。

这是我的代码

代码语言:javascript
复制
 * createUser
 * @param {string} email
 * @param {string} password
 * @param {string} name
 */
const createUser = async (email, password, name) => {
  const user = await getUser(email);
  if (user) throw new Error('User account already exists');

  bcrypt.genSalt(10, (salt) => {
    bcrypt.hash(password, salt, (hashedPassword) => {
      db.collection('users')
        .doc(email)
        .set({ hashedPassword, email, name });
    });
  });
};

我收到了这个错误

代码语言:javascript
复制
        throw new Error(validate_1.customObjectMessage(arg, value, path));
        ^

Error: Value for argument "data" is not a valid Firestore document. Input is not a plain JavaScript object (found in field "hashedPassword").
    at Object.validateUserInput (/home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/@google-cloud/firestore/build/src/serializer.js:301:15)
    at validateDocumentData (/home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/@google-cloud/firestore/build/src/write-batch.js:620:22)
    at WriteBatch.set (/home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/@google-cloud/firestore/build/src/write-batch.js:234:9)
    at DocumentReference.set (/home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/@google-cloud/firestore/build/src/reference.js:340:14)
    at /home/abdessalem/Desktop/tutum/test/simple-auth-app/src/firestore/index.js:54:10
    at /home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/bcrypt/bcrypt.js:140:13
    at processTicksAndRejections (internal/process/task_queues.js:79:11)
EN

回答 1

Stack Overflow用户

发布于 2020-04-08 02:37:45

哈希很可能是作为可读的流返回的,在这种情况下,您可以使用以下方法对其进行十六进制编码:

代码语言:javascript
复制
hashedPassword.toString("hex")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61090621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档