
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