Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.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
Javascript NodeJs的BCrypt包的hash()和hashSync()函数之间的差异 const bcrypt=require('bcrypt') 常量哈希=bcrypt.hash(,12) 常量hashSync=bcrypt.hashSync(,12)_Javascript_Node.js_Passwords_Bcrypt_Password Hash - Fatal编程技术网

Javascript NodeJs的BCrypt包的hash()和hashSync()函数之间的差异 const bcrypt=require('bcrypt') 常量哈希=bcrypt.hash(,12) 常量hashSync=bcrypt.hashSync(,12)

Javascript NodeJs的BCrypt包的hash()和hashSync()函数之间的差异 const bcrypt=require('bcrypt') 常量哈希=bcrypt.hash(,12) 常量hashSync=bcrypt.hashSync(,12),javascript,node.js,passwords,bcrypt,password-hash,Javascript,Node.js,Passwords,Bcrypt,Password Hash,它们在哪些方面可能有所不同,并且可以互换使用? (非常欢迎并非常感谢您的详细解释!)bcrypt.hash将回调作为其第三个参数,在完成哈希时将调用该参数。 bcrypt.hashSync运行哈希,等待它完成并返回哈希值 换句话说,“hash”是异步的,hashSync是同步的。bcrypt.hash将回调作为其第三个参数,当hash完成时将调用该参数。 bcrypt.hashSync运行哈希,等待它完成并返回哈希值 换句话说,“hash”是异步的,hashSync是同步的。你的意思是 cons

它们在哪些方面可能有所不同,并且可以互换使用?
(非常欢迎并非常感谢您的详细解释!)

bcrypt.hash将回调作为其第三个参数,在完成哈希时将调用该参数。 bcrypt.hashSync运行哈希,等待它完成并返回哈希值


换句话说,“hash”是异步的,hashSync是同步的。

bcrypt.hash将回调作为其第三个参数,当hash完成时将调用该参数。 bcrypt.hashSync运行哈希,等待它完成并返回哈希值

换句话说,“hash”是异步的,hashSync是同步的。

你的意思是

const bcrypt = require('bcrypt')

const hash = bcrypt.hash(<myPassword>, 12)

const hashSync = bcrypt.hashSync(<myPasword>, 12)
const bcrypt=require('bcrypt')
const hash=bcrypt.hash(,12)//这将返回一个承诺
const hashSync=bcrypt.hashSync(,12)//这是同步的,所以它会在执行之后停止每一行代码
阅读这篇文章,了解同步和异步之间的区别

const bcrypt = require('bcrypt')

const hash = bcrypt.hash(<myPassword>, 12)

const hashSync = bcrypt.hashSync(<myPasword>, 12)
const bcrypt=require('bcrypt')
const hash=bcrypt.hash(,12)//这将返回一个承诺
const hashSync=bcrypt.hashSync(,12)//这是同步的,所以它会在执行之后停止每一行代码
阅读文章了解同步和异步之间的区别,hashSync用于同步生成给定字符串的哈希。它返回散列字符串

哈希用于异步生成给定字符串的哈希。当回调被提交时,它返回承诺,您需要解决该承诺

提及

hashSync用于同步生成给定字符串的哈希。它返回散列字符串

哈希用于异步生成给定字符串的哈希。当回调被提交时,它返回承诺,您需要解决该承诺

提及


为了快速理解,我记录了值“myPassword”的“hash”和“hashSync”的值:
hash:Promise{}
hashSync:$2b$12$xEpu8E8s0FGIC2wgYbacSO.kombqseoobhxv3uwu.h/amo99Wg6
,它就是这么做的。非同步版本返回承诺而不是直接值。这是否回答了您的问题?为了快速理解,我记录了值“myPassword”的“hash”和“hashSync”的值:
hash:Promise{}
hashSync:$2b$12$xEpu8E8s0FGIC2wgYbacSO.kombqseoobhxv3uwu.h/amo99Wg6
,它就是这么做的。非同步版本返回承诺而不是直接值。这是否回答了您的问题?