nodejs 用戶密碼存儲加密設(shè)計

While there are other lightweight packages or built-in Node.js functions for hashing and salting passwords, bcrypt is widely used and has a proven track record of providing strong security. Therefore, it is a good choice for securing passwords in a database.

Package Name Description
bcrypt Hash and salt passwords using the Blowfish encryption algorithm
argon2 Hash passwords using the Argon2 algorithm, which is resistant to side-channel attacks
scrypt Hash passwords using the scrypt algorithm, which is resistant to GPU and ASIC attacks
pbkdf2 Hash passwords using the PBKDF2 algorithm, which is based on HMAC-SHA1
crypto Built-in Node.js package for encrypting data, including passwords
libsodium Cryptography library that includes password hashing functions
passlib Python library for hashing and verifying passwords
jBCrypt Java implementation of the Blowfish password hashing algorithm
hashids Generate short, unique, and reversible ids from integers
shortid Generate short and unique ids for use in URLs and other contexts

Here are five popular ways to hash and salt passwords in Node.js:

Bcrypt: Bcrypt is a widely used password hashing function that is known for its security and resistance to brute-force attacks. It is a popular choice for password hashing in many Node.js applications.

Argon2: Argon2 is a newer password hashing function that is designed to be more secure than bcrypt. It uses a variable amount of memory and time to hash passwords, which makes it resistant to brute-force attacks and other types of attacks.

PBKDF2: PBKDF2 is a key derivation function that is often used for password hashing. It is a slow, computationally intensive algorithm that can be configured to use multiple iterations and a salt to make it more secure.

SHA-256: SHA-256 is a hash function that is commonly used for password hashing. While it is not as secure as some other hashing functions, it is still a popular choice for password hashing in many applications.

Scrypt: Scrypt is a password-based key derivation function that is designed to be memory-hard and resistant to brute-force attacks. It is similar to Argon2 in many ways, but is not as widely used.

Here are five popular lightweight packages for hashing and salting passwords in Node.js that don't require any compilation:

bcryptjs: A pure JavaScript implementation of the bcrypt password hashing function that works on both Node.js and web browsers. It is a drop-in replacement for bcrypt.

crypto-js: A JavaScript library that provides a collection of cryptographic algorithms including password-based key derivation functions like PBKDF2 and SHA256. It can be used in both Node.js and web browsers.

scrypt: A pure JavaScript implementation of the scrypt password-based key derivation function. It is optimized for the V8 JavaScript engine and works in both Node.js and web browsers.

argon2: A pure JavaScript implementation of the Argon2 password hashing function. It is optimized for the V8 JavaScript engine and works in both Node.js and web browsers.

node-forge: A pure JavaScript implementation of cryptographic algorithms including password-based key derivation functions like PBKDF2 and bcrypt. It can be used in both Node.js and web browsers.

The reason for using bcrypt to generate a salted hash of a password and to compare it with the stored hash is that it provides a more secure way of storing and managing passwords than simply storing them in plaintext.

Bcrypt is a popular password hashing function that uses a combination of a key derivation function (KDF) and a salt to hash a password. By using a KDF, bcrypt can slow down an attacker attempting to crack the password by requiring them to perform a large number of iterations of the KDF. This is known as key strengthening or key stretching.

Additionally, using a salt helps to protect against pre-computed hash attacks, where an attacker could use a pre-computed table of hashes to quickly crack passwords. By using a unique salt for each password, the attacker would need to generate a new table of hashes for each salt, making the attack much more difficult and time-consuming.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末扎运,一起剝皮案震驚了整個濱河市疆栏,隨后出現(xiàn)的幾起案子饺鹃,更是在濱河造成了極大的恐慌粱檀,老刑警劉巖蝇刀,帶你破解...
    沈念sama閱讀 216,997評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件搓萧,死亡現(xiàn)場離奇詭異讳窟,居然都是意外死亡窘俺,警方通過查閱死者的電腦和手機饲帅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,603評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來瘤泪,“玉大人灶泵,你說我怎么就攤上這事《酝荆” “怎么了赦邻?”我有些...
    開封第一講書人閱讀 163,359評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長实檀。 經(jīng)常有香客問我惶洲,道長,這世上最難降的妖魔是什么膳犹? 我笑而不...
    開封第一講書人閱讀 58,309評論 1 292
  • 正文 為了忘掉前任恬吕,我火速辦了婚禮,結(jié)果婚禮上须床,老公的妹妹穿的比我還像新娘铐料。我一直安慰自己,他們只是感情好豺旬,可當我...
    茶點故事閱讀 67,346評論 6 390
  • 文/花漫 我一把揭開白布钠惩。 她就那樣靜靜地躺著,像睡著了一般族阅。 火紅的嫁衣襯著肌膚如雪篓跛。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,258評論 1 300
  • 那天坦刀,我揣著相機與錄音愧沟,去河邊找鬼。 笑死鲤遥,一個胖子當著我的面吹牛央渣,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播渴频,決...
    沈念sama閱讀 40,122評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼北启!你這毒婦竟也來了卜朗?” 一聲冷哼從身側(cè)響起拔第,我...
    開封第一講書人閱讀 38,970評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎场钉,沒想到半個月后蚊俺,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,403評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡逛万,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,596評論 3 334
  • 正文 我和宋清朗相戀三年泳猬,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片宇植。...
    茶點故事閱讀 39,769評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡得封,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出指郁,到底是詐尸還是另有隱情忙上,我是刑警寧澤,帶...
    沈念sama閱讀 35,464評論 5 344
  • 正文 年R本政府宣布闲坎,位于F島的核電站疫粥,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏腰懂。R本人自食惡果不足惜梗逮,卻給世界環(huán)境...
    茶點故事閱讀 41,075評論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望绣溜。 院中可真熱鬧慷彤,春花似錦、人聲如沸涮毫。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,705評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽罢防。三九已至艘虎,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間咒吐,已是汗流浹背野建。 一陣腳步聲響...
    開封第一講書人閱讀 32,848評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留恬叹,地道東北人候生。 一個月前我還...
    沈念sama閱讀 47,831評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像绽昼,于是被迫代替她去往敵國和親唯鸭。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,678評論 2 354

推薦閱讀更多精彩內(nèi)容