Node Typescript에서 패스워드 > RESTful

RESTful

Node Typescript에서 패스워드 정보

Node Typescript에서 패스워드

본문

https://sir.kr/so_restful/16

 

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

댓글 0개

전체 96 |RSS
RESTful 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT