(완료)1. node 3주차 과제 배포까지 해보기
2. 강의 듣기
3. 스터디 준비
찾기 find => select, where
만들기 create => data
처음엔 삼항 연산자의❓를 오타낸건가❓ 아니면 뭐지❓❓ 했다. 찾아보니 널 병합 연산자라는 것.
왼쪽의 값이
null이거나undefined라면 오른쪽의 값을 할당.
왼쪽의 값이 있다면 그냥 왼쪽 값.
const a = { duration: 50 }; a.duration ??= 10; // console.log(a.duration); // Expected output: 50
a.duration값은 50이다. 왼쪽인a.duration의 값이 있기때문에 널 병합 연산자에 의해 오른쪽 값인 10이 할당되지 않는다.
const a = { duration: 50 }; a.speed ??= 25; console.log(a.speed); // Expected output: 25
- 그에 반해
a.speed는undefined이기 때문에 오른쪽의 값인 25가 할당된다.
입력받은 데이터 -> 특정 암호화 알고리즘 이용 -> 암호화 및 검증을 도와주는 모듈
yarn add bcrypt
import bcrypt from 'bcrypt'; const password = 'Sparta'; // 사용자의 비밀번호 const saltRounds = 10; // salt를 얼마나 복잡하게 만들지 결정합니다. // 'hashedPassword'는 암호화된 비밀번호 입니다. const hashedPassword = await bcrypt.hash(password, saltRounds); console.log(hashedPassword); //$2b$10$OOziCKNP/dH1jd.Wvc3JluZVm7H8WXR8oUmxUQ/cfdizQOLjCXoXa
import bcrypt from 'bcrypt'; const password = 'Sparta'; // 사용자가 입력한 비밀번호 const hashed = '$2b$10$OOziCKNP/dH1jd.Wvc3JluZVm7H8WXR8oUmxUQ/cfdizQOLjCXoXa'; // DB에서 가져온 암호화된 비밀번호 // 'result'는 비밀번호가 일치하면 'true' 아니면 'false' const result = await bcrypt.compare(password, hashed); console.log(result); // true // 비밀번호가 일치하지 않다면, 'false' const failedResult = await bcrypt.compare('FailedPassword', hashed); console.log(failedResult); // false