可以在bcrypt哈希中使用冒号和下划线字符吗??

问题描述 投票:0回答:1

[我相信...从一些研究中可以看出,bcrypt允许将任何类型的字符都进行哈希处理...但是,我正在寻找对此的验证。我有以下代码会产生两个连续的bcrypt哈希,第一个用于密码,第二个用于名称。密码的哈希有效,没有任何问题。该名称的哈希不起作用...它将“未定义”写入数据库。此名称包含一些特殊字符,例如下划线(_)和冒号(“:”)...这些字符是否可以用于哈希生成?

const processes = require('./routes/processes');
namex = String(name) + String("_0:") + String(_year + _month + _day);

processes.hashPassword(password)
.then(function(hashedPassword) {
 newHash = hashedPassword;  //this works fine, returns a hash 
})
.then(processes.hashName(namex))  
.then(function(hashedName) {
 newName = hashedName;  //this returns 'undefined'...is not working...because of the special characters???
})
//code to write to database here...
node.js character bcrypt
1个回答
0
投票

如果有人需要将来参考,我可以使用以下代码修改来解决此问题:

const processes = require('./routes/processes');
namex = String(name) + String("_0:") + String(_year + _month + _day);

processes.hashPassword(password)
.then(function(hashedPassword) {
 newHash = hashedPassword;  //this works fine, returns a hash
 return processes.hashName(namex);  
  //NOTE:  The 'return' is CRITICAL to prevent an 'undefined' result 
  //for 'hashedName' in following '.then' statement...!!!
})
.then(function(hashedName) {
 newName = hashedName;  //this works fine, returns a hash
})
//code to write to database here... 

解决此问题的关键是在调用后续诺言时添加'return'语句。这样做时,我设法避免了“未定义”的结果。非常感谢此处的这篇文章:“ https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html”帮助我解决了此问题。

© www.soinside.com 2019 - 2024. All rights reserved.