일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- evm
- built in object
- 삶
- Ethereum
- bitcoin
- SSR
- tailwindcss
- Redux
- Props
- useState
- solidity
- HTML
- nextJS
- typeScript
- middleware
- concept
- express.js
- hardhat
- 기준
- blockchain
- web
- CSS
- Interface
- node.js
- graphQL
- API
- REACT
- CLASS
- JavaScript
- error
- Today
- Total
ReasonJun
bcryptjs (encryption method) 본문
bcryptjs is a library used for hashing passwords in JavaScript. It provides a way to securely hash passwords and compare them with hashed values to verify if a password is correct. The library is a JavaScript implementation of the bcrypt algorithm, which is a widely used and respected password-hashing algorithm.
Here are some key features and usage details of bcryptjs:
- Hashing passwords: You can use bcryptjs to hash passwords by calling the hash function. It takes the plain text password and a salt value (which can be generated using genSaltSync or genSalt) and returns the hashed password.
const bcrypt = require('bcryptjs');
const plainPassword = 'myPassword';
const salt = bcrypt.genSaltSync(10);
const hashedPassword = bcrypt.hashSync(plainPassword, salt);
- Comparing passwords: You can compare a plain text password with a hashed password to determine if they match using the compare function. It takes the plain text password and the hashed password and returns a boolean indicating whether they match.
const bcrypt = require('bcryptjs');
const plainPassword = 'myPassword';
const hashedPassword = '$2a$10$Rau3qZKm4bJF52k.8roaoOPO4v./6h4noNNU29N/Vt.g1.2KpRqq2';
const isMatch = bcrypt.compareSync(plainPassword, hashedPassword);
console.log(isMatch); // true
- Generating salt: genSalt or genSaltSync functions are used to generate a salt value. The salt is a random string used to further strengthen the password hashing process.
const bcrypt = require('bcryptjs');
// Asynchronous version
bcrypt.genSalt(10, (err, salt) => {
// Use the salt value
});
// Synchronous version
const salt = bcrypt.genSaltSync(10);
Note: The cost factor (e.g., 10 in the examples) determines the computational cost of the hashing process and should be chosen based on the desired security level and system performance.
bcryptjs is commonly used in Node.js and JavaScript applications for securely storing and verifying passwords. It is recommended over simpler hashing functions like MD5 or SHA256 because bcrypt employs techniques such as salting and multiple rounds of hashing to protect against brute-force attacks and rainbow table attacks.
https://www.npmjs.com/package/bcryptjs
'Frontend > Library' 카테고리의 다른 글
Framer Motion (0) | 2023.07.10 |
---|---|
Cloudinary (0) | 2023.07.10 |
PostCSS & AutoFixer (0) | 2023.06.29 |
react-hook-form (useForm()) (0) | 2023.06.23 |
Web Vitals : LCP / FID / CLS & Measure Performance / Lighthouse (0) | 2023.06.21 |