고요빛물결
RESTful

Node Typescript에서 패스워드

· 2021-01-18 (월) 00:45:40 · 1085

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에 있는 키와 새로 만든 키가 같으면 성공, 틀리면 실패

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

소모임

23,243건
+
분류 제목 글쓴이 날짜 조회
해외사용자 21-01-22 조회 1,536
해외사용자
[해외사용자]
21-01-22 조회 1,618
RESTful 21-01-22 조회 1,305
RESTful 21-01-22 조회 1,586
RESTful 21-01-21 조회 1,487
RESTful 21-01-21 조회 1,271
모형취미 21-01-20 조회 2,153
RESTful 21-01-20 조회 1,312
해외사용자 21-01-19 조회 1,821
RESTful 21-01-19 조회 1,353
RESTful 21-01-19 조회 1,316
RESTful 21-01-18 조회 1,086
RESTful 21-01-17 조회 1,545
RESTful 21-01-17 조회 1,637
PHP프레임워크 21-01-17 조회 2,603
RESTful 21-01-16 조회 2,077
RESTful 21-01-16 조회 2,152
RESTful 21-01-16 조회 1,219
해외사용자 21-01-16 조회 1,338
RESTful 21-01-15 조회 1,437
RESTful 21-01-15 조회 1,336
해외사용자 21-01-15 조회 1,816
RESTful 21-01-14 조회 1,159
RESTful 21-01-14 조회 1,248
Node.js 21-01-14 조회 1,486
RESTful 21-01-14 조회 1,950
RESTful 21-01-13 조회 1,118
RESTful 21-01-12 조회 1,285
RESTful 21-01-12 조회 2,192
해외사용자 21-01-12 조회 1,873