Node Typescript에서 패스워드

· 5년 전 · 746

https://sir.kr/so_restful/16

 

import를 하는 방법을 몰라서 헤멨네요

 

패스워드 체크하는 것도 안 적어놔서 모르겠네요.  atob를 썼던 것 같은데,  지금 해보니 없어도 되네요.

 

옛날 코드를 아무리 찾아도 없어서, 그냥 구현했는데,  

 

고수님들 보시고 알려주세요.

 

[code]

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;

[/code]

 

[code]

        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;

[/code]

 

> mb_password에 저장된 4개의 필드를 읽어옴

> 들어온 패스워드(in_password)를 사용해서 새로운 키를 만듬.

> mb_password에 있는 키와 새로 만든 키가 같으면 성공, 틀리면 실패

|
댓글을 작성하시려면 로그인이 필요합니다.

RESTful

+
제목 글쓴이 날짜 조회
5년 전 조회 890
5년 전 조회 1,442
5년 전 조회 740
5년 전 조회 1,149
5년 전 조회 1,708
5년 전 조회 1,455
5년 전 조회 1,423
5년 전 조회 1,046
5년 전 조회 1,245
5년 전 조회 1,181
5년 전 조회 1,019
5년 전 조회 1,033
5년 전 조회 991
5년 전 조회 1,029
5년 전 조회 747
5년 전 조회 1,181
5년 전 조회 1,239
5년 전 조회 1,750
5년 전 조회 1,869
5년 전 조회 896
5년 전 조회 1,120
5년 전 조회 1,005
5년 전 조회 881
5년 전 조회 978
5년 전 조회 1,588
5년 전 조회 849
5년 전 조회 1,008
5년 전 조회 1,922
5년 전 조회 2,927
5년 전 조회 1,240