Node Typescript에서 패스워드 정보
Node Typescript에서 패스워드
본문
import를 하는 방법을 몰라서 헤멨네요
패스워드 체크하는 것도 안 적어놔서 모르겠네요. atob를 썼던 것 같은데, 지금 해보니 없어도 되네요.
옛날 코드를 아무리 찾아도 없어서, 그냥 구현했는데,
고수님들 보시고 알려주세요.
import * as btoa from 'btoa';
import * as crypto from 'crypto';
import * as pbkdf2 from 'pbkdf2';
const dkLen = 24;
const iterations = 12000;
const algorithm = 'sha256';
const salt = btoa(crypto.randomBytes(24));
var derivedKey = btoa(pbkdf2.pbkdf2Sync(this.mbPassword, salt, iterations, dkLen, algorithm));
mb_psassword = algorithm + ':' + iterations + ':' + salt + ':' + derivedKey;
const dkLen = 24;
const [algorithm, iterations, salt, derivedKey] = mb_password.split(':');
const newDerivedKey = btoa(pbkdf2.pbkdf2Sync(attempt, salt, Number(iterations), dkLen, algorithm));
if(newDerivedKey === derivedKey) {
return true;
}
return false;
> mb_password에 저장된 4개의 필드를 읽어옴
> 들어온 패스워드(in_password)를 사용해서 새로운 키를 만듬.
> mb_password에 있는 키와 새로 만든 키가 같으면 성공, 틀리면 실패
!-->!-->
추천
2
2
댓글 0개