개발자 Q&A

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

2025.06.30 22:44

질문 sodium_crypto_pwhash_scryptsalsa208sha256_str_verify 함수 사용 방법에 대한 도움을 요청합니다.

목록
  • Perl매니아 19일 전 2025.06.30 22:44
  • 60
    1
제가 현재 sodium_crypto_pwhash_scryptsalsa208sha256_str_verify 함수를 사용하여 비밀번호를 검증하는 중인데, 함수의 인자로 전달하는 salt와 hashed password를 어떻게 생성하는지 잘 이해가 가지 않습니다.

salt를 생성하는 함수는 sodium_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash 함수를 사용하는 것 같은데, 이 함수의 반환값을 salt로 사용할 수 있나요?

또한, hashed password를 생성하는 함수는 sodium_crypto_pwhash_scryptsalsa208sha256 함수를 사용하는 것 같은데, 이 함수의 반환값을 hashed password로 사용할 수 있나요?

위 함수를 사용하여 비밀번호를 검증하는 예제 코드를 부탁드립니다.

    댓글목록

    profile_image
    나우호스팅  19일 전



    sodium_crypto_pwhash_scryptsalsa208sha256_str_verify 함수를 사용하여 비밀번호를 검증하는 방법에 대한 설명입니다.

    sodium_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash 함수의 반환값을 salt로 사용할 수 있습니다. 이 함수는 salt가 필요로 하는 크기를 반환하며, 이 크기는 sodium_crypto_pwhash_scryptsalsa208sha256 함수의 salt 인자로 사용됩니다.

    sodium_crypto_pwhash_scryptsalsa208sha256 함수의 반환값을 hashed password로 사용할 수 있습니다. 이 함수는 salt와 password를 인자로 받아 hashed password를 반환합니다.

    위 함수를 사용하여 비밀번호를 검증하는 예제 코드는 다음과 같습니다.

    #hostingforum.kr
    c
    
    #include 
    
    
    
    int main() {
    
        // salt를 생성하는 함수는 sodium_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash 함수를 사용하는 것 같은데, 
    
        // 이 함수의 반환값을 salt로 사용할 수 있나요?
    
        unsigned char salt[32];
    
        unsigned int salt_len = 32;
    
        if (sodium_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash(salt, &salt_len, NULL, 0, NULL, 0)) {
    
            // salt가 필요로 하는 크기가 반환되었습니다.
    
        }
    
    
    
        // hashed password를 생성하는 함수는 sodium_crypto_pwhash_scryptsalsa208sha256 함수를 사용하는 것 같은데, 
    
        // 이 함수의 반환값을 hashed password로 사용할 수 있나요?
    
        unsigned char hashed_password[32];
    
        unsigned int hashed_password_len = 32;
    
        if (sodium_crypto_pwhash_scryptsalsa208sha256(salt, salt_len, "password", strlen("password"), &hashed_password_len, hashed_password)) {
    
            // hashed password가 생성되었습니다.
    
        }
    
    
    
        // 비밀번호를 검증하는 함수는 sodium_crypto_pwhash_scryptsalsa208sha256_str_verify 함수를 사용합니다.
    
        if (sodium_crypto_pwhash_scryptsalsa208sha256_str_verify(salt, salt_len, "password", strlen("password"), hashed_password, hashed_password_len)) {
    
            // 비밀번호가 올바르게 검증되었습니다.
    
        } else {
    
            // 비밀번호가 올바르게 검증되지 않았습니다.
    
        }
    
    
    
        return 0;
    
    }
    
    


    위 예제 코드는 sodium_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash 함수를 사용하여 salt를 생성하고, sodium_crypto_pwhash_scryptsalsa208sha256 함수를 사용하여 hashed password를 생성한 후, sodium_crypto_pwhash_scryptsalsa208sha256_str_verify 함수를 사용하여 비밀번호를 검증합니다.

    2025-06-30 22:45

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

검색

게시물 검색