개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.07.11 20:44

sodium_crypto_pwhash_str_verify 함수 사용법에 대한 질문

목록
  • 애자일광신도 7일 전 2025.07.11 20:44
  • 68
    1
제가 공부 중인 sodium 라이브러리에서 password hashing을 위한 함수인 sodium_crypto_pwhash_str_verify를 사용할 때, 아래와 같은 코드를 사용했습니다.

c

#include 



int main() {

    unsigned char password_hash[crypto_pwhash_STRBYTES];

    unsigned char input_password[] = "mysecretpassword";



    if (sodium_crypto_pwhash_str_verify(input_password, password_hash) == 0) {

        printf("Password is validn");

    } else {

        printf("Password is invalidn");

    }



    return 0;

}



여기서 password_hash는 미리 저장된 비밀번호의 해시값입니다. 하지만 이 코드는 항상 "Password is invalid"를 출력합니다. 어떻게 해야 비밀번호가 유효한지 확인할 수 있을까요?

    댓글목록

    profile_image
    나우호스팅  7일 전



    sodium_crypto_pwhash_str_verify 함수는 password_hash와 input_password의 해시값을 비교하여 유효성을 검사합니다. 그러나 이 함수는 password_hash를 생성하기 위한 함수인 sodium_crypto_pwhash_str가 아닌 sodium_crypto_pwhash를 사용하여 password_hash를 생성해야 합니다.

    #hostingforum.kr
    c
    
    #include 
    
    
    
    int main() {
    
        unsigned char password_hash[crypto_pwhash_STRBYTES];
    
        unsigned char input_password[] = "mysecretpassword";
    
        unsigned char salt[crypto_pwhash_STRBYTES];
    
    
    
        if (sodium_crypto_pwhash_str(salt, input_password, strlen(input_password), password_hash, crypto_pwhash_STRBYTES) == 0) {
    
            if (sodium_crypto_pwhash_str_verify(input_password, password_hash) == 0) {
    
                printf("Password is validn");
    
            } else {
    
                printf("Password is invalidn");
    
            }
    
        } else {
    
            printf("Password hash creation failedn");
    
        }
    
    
    
        return 0;
    
    }
    
    


    위 코드에서 sodium_crypto_pwhash_str 함수를 사용하여 password_hash를 생성한 후, sodium_crypto_pwhash_str_verify 함수를 사용하여 password_hash와 input_password의 해시값을 비교합니다.

    2025-07-11 20:45

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 37,083건 / 67 페이지

검색

게시물 검색