2017-11-14 16 views
0

암호를 해시하고 데이터베이스에 저장하려고합니다. 그래서 libpodium을 crypto_pwhash와 함께 노드 응용 프로그램에 사용합니다. 함수를 생성하고 내보내지만 해시 비밀번호를받을 수 없습니다. sodium.js콜백 값을 사용하여 libsodium 함수를 호출하십시오.

libsodium = require('libsodium-wrappers-sumo'); 
(async() => { 
await libsodium.ready; 
const sodium = libsodium; 

module.exports.password_hash = function(password, res){ 
var hashed_password = [sodium.crypto_pwhash_STRBYTES]; 
if (sodium.crypto_pwhash_str (sodium.crypto_pwhash_MEMLIMIT_SENSITIVE) != 0){ 
    /* out of memory */ 
} 
    return res(hashed_password); 
} 
/*if (sodium.crypto_pwhash_str_verify 
(hashed_password, PASSWORD, strlen(PASSWORD)) != 0) { 
/* wrong password */ 
//} 
})(); 

sodium.password_hash("test", function(res){ 
     console.log(res); 
    }); 

오류 메시지가 app.js : 암호 지원되지 않는 입력 타입

여기 내 코드입니다. 내가 잘못

업데이트 무엇인지 이해하지 못하는

: 난 내 코드를 updade 이제 메시지 오류입니다 : 정의 할 때, 출력 형식은 내가 배열에 문제라고 생각 문자열 해야합니다

+0

그것은 당신이 어떤 브래킷을 누락 것 같습니다 때문에 sodium.js''에서 무엇을하고 있는지 이해하기 어렵다은 없습니다. 이것을 편집하여 유효한 js가 될 수 있습니까? –

+0

내 게시물을 업데이트하지만 몇 줄이 더 있습니다. – Vana

+0

암호를 해시 할 함수에 암호를 지정해야합니다. –

답변

0

이 문자열로 해시 암호를 반환 sodium.crypto_pwhash_str, 필요 첫 번째 매개 변수