Files
mtusi2026lab7/student-tests/auth_security_test.cpp
2026-11-26 23:34:55 +03:00

20 lines
911 B
C++

#include "auth.hpp"
#include <sodium.h>
#include <cassert>
#include <chrono>
#include <iostream>
int main() {
const auto start = std::chrono::steady_clock::now();
const auto hash = hash_password("correct horse battery staple");
assert(hash.rfind("$argon2id$v=19$m=65536,t=2,p=1$",0)==0);
assert(verify_password("correct horse battery staple",hash));
assert(!verify_password("wrong",hash));
assert(!verify_password("wrong","$argon2id$malformed"));
assert(!password_needs_rehash(hash));
char old[crypto_pwhash_STRBYTES];
assert(crypto_pwhash_str_alg(old,"password",8,1,19*1024*1024,crypto_pwhash_ALG_ARGON2ID13)==0);
assert(password_needs_rehash(old));
std::cout << "PASS: Argon2id m=65536 KiB,t=2,p=1; verify/malformed/rehash; total_ms="
<< std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now()-start).count() << '\n';
}