```
MySql Nodejs Bcrypt 암호화 설정하는 한 가지 꿀팁
```

목차
- DB 컬럼 설정
- Nodejs bcrypt 설치 및 세팅
- 비밀번호 입력(Nodejs)
- 비밀번호 입력(SQL 예시)
- 비밀번호 비교
- 참조
DB 컬럼 설정
bcrypt 암호화의 경우 BINARY(40)을 쓰는 것이 정석이나
이경우 hash 값을 deconstruct 해야 하기 때문에
BINARY(60)으로 설정해서 쓰는 게 마음에 편합니다
Nodejs bcrypt 설치 및 세팅
npm 혹은 yarn으로 설치
npm install bcrypt
아래와 같이 사용
const bcrypt = require('bcrypt');
const saltRounds = 10;
salt 값을 사용해서 하나의 bcrypt hash를 계산하는데 필요한 연산을 조절합니다
소규모 프로젝트의 경우 salt 값 10을 많이 사용합니다
비밀번호 입력(Nodejs)
const password = req.body.password;
const encryptedPassword = await bcrypt.hash(password, saltRounds)
encryptedPassword를 저장해 주면 됩니다
비밀번호 비교
const comparison = await bcrypt.compare(password, results[0].password)
if(!comparison){/*fail*/}
참조 및 유용한 사이트
Bcrypt-Generator.com - Online Bcrypt Hash Generator and Checker
Bcrypt-Generator.com is a online tool to check Bcrypt hashes. You can also use it to generate new Bcrypt hashes for your other applications that require a Bcrypt encrypted string or password
bcrypt-generator.com
Bcrypt Hash Generator & Verifier
Generate Bcrypt password hashes with desired cost option. Verify/Validate existing Bcrypt hashes.
bcrypt.online
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
'DB' 카테고리의 다른 글
| PostgreSQL16 pgadmin4 DB Backup and Restore 해보기 (0) | 2024.01.20 |
|---|---|
| SQL The user specified as a definer ('root'@'%') does not exist 해결하는 한가지 방법 (0) | 2023.11.01 |
| PostgreSQL에서 값이 존재하는지 확인하는 한가지 방법 / Exists (0) | 2023.01.07 |
| String으로 PK 만들때 Performance 높이는 한가지 방법 (1) | 2022.11.23 |
| 생각) SQL 서버에서 공백문자열을 쓰는게 NULL을 쓰는것 보다 좋은 한가지 이유 (0) | 2022.10.31 |