
	                	                 
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