我需要将明确的密码交换为散列的密码。我正在使用bcryptjs来帮助我。
我曾尝试分配明确使用哈希密码的密码,但是我在bash上遇到错误。
我正在尝试的代码:
const bcrypt = require('bcryptjs');
const students = require('./students1.json');
const fs = require('fs');
let secureUsers = [];
for (let student of students) {
let salt = bcrypt.genSaltSync(10);
let passHash = bcrypt.hashSync(student.password, salt);
Object.assign(student.password, passHash);
secureUsers.push(secStudent);
}
fs.writeFileSync('secStudents.json', JSON.stringify(secureUsers, null, 2));
console.log('wrote file!');
我得到的错误:
$ node bcryptExample.js
C:\Users\mziad\assignment-mziadeh1\servers\bcryptExample.js:13
Object.assign(student.password, passHash);
^
TypeError: Cannot assign to read only property '0' of object '[object String]'
at Function.assign (<anonymous>)
at Object.<anonymous> (C:\Users\mziad\assignment-mziadeh1\servers\bcryptExample.js:13:12)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
我想要散列的示例:
{
"netid": "ky4531",
"firstName": "Frankie",
"lastName": "Griffith",
"email": "erasement1803@outlook.com",
"password": "t'|x/)$g"
},
{
"netid": "tw0199",
"firstName": "Julietta",
"lastName": "Vargas",
"email": "ezekiel1960@outlook.com",
"password": "Rc*pKe$w"
}
我需要将密码与哈希码交换,因此为什么要尝试分配密码。但是我遇到了一个我不理解的错误,我现在无法真正发现我的代码有任何问题。
桃花长相依
相关分类