Introduce Authenticator: Centralizes Authentication/password check logic

This commit is contained in:
2021-03-26 22:48:26 +01:00
부모 e322587d07
커밋 5693911e01
2개의 변경된 파일138개의 추가작업 그리고 0개의 파일을 삭제

30
authenticator.h Normal file
파일 보기

@@ -0,0 +1,30 @@
#ifndef AUTHENTICATOR_H
#define AUTHENTICATOR_H
#include <variant>
#include "database/userdao.h"
enum AuthenticationError
{
UserNotFound,
UserDisabled,
PasswordNotMatch,
BannedIP,
GeneralError
};
class Authenticator
{
private:
UserDao *userDao;
bool isBanned(std::string ip);
void incFailureCount(std::string ip);
std::vector<char> pbkdf5(std::string password, const std::vector<char> &salt);
public:
Authenticator(UserDao &userDao);
std::variant<User, AuthenticationError> authenticate(std::string username, std::string password);
std::variant<User, AuthenticationError> authenticate(std::string username, std::string password, std::string ip);
std::vector<char> hash(std::string password, const std::vector<char> &salt);
};
#endif // AUTHENTICATOR_H