Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 是否可以在bcrypt哈希中使用冒号和下划线字符。。。?_Node.js_Character_Bcrypt - Fatal编程技术网

Node.js 是否可以在bcrypt哈希中使用冒号和下划线字符。。。?

Node.js 是否可以在bcrypt哈希中使用冒号和下划线字符。。。?,node.js,character,bcrypt,Node.js,Character,Bcrypt,我相信…从一些研究中,bcrypt允许任何类型的字符被接受进行散列…但是我希望对此进行一些验证。下面的代码生成两个连续的bcrypt哈希,第一个用于密码,第二个用于名称。 密码的哈希值可以正常工作。名称的哈希不起作用…它将“未定义”写入数据库。此名称包含一些特殊字符,例如下划线(“”)和冒号(:”)。是否允许在哈希生成中使用这些字符 const processes = require('./routes/processes'); namex = String(name) + String("_0

我相信…从一些研究中,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...

如果有人需要将来参考,我可以通过以下代码修改来解决这个问题:

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”语句。这样做时,我设法避免了“未定义”的结果。非常感谢这篇文章:“帮助我解决了这个问题