Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/backends/nntpchan-daemon/src/nntp_auth.hpp

58 lines
1.5 KiB
C++
Raw Normal View History

2016-10-15 21:37:59 +05:00
#ifndef NNTPCHAN_NNTP_AUTH_HPP
#define NNTPCHAN_NNTP_AUTH_HPP
#include <string>
#include <iostream>
2016-10-15 22:53:35 +05:00
#include <fstream>
2016-10-15 21:37:59 +05:00
#include <mutex>
#include "line.hpp"
namespace nntpchan
{
/** @brief nntp credential db interface */
class NNTPCredentialDB
{
public:
2016-10-15 22:53:35 +05:00
/** @brief open connection to database, return false on error otherwise return true */
virtual bool Open() = 0;
/** @brief close connection to database */
virtual void Close() = 0;
2016-10-15 21:37:59 +05:00
/** @brief return true if username password combo is correct */
virtual bool CheckLogin(const std::string & user, const std::string & passwd) = 0;
2016-10-15 22:53:35 +05:00
virtual ~NNTPCredentialDB() {}
2016-10-15 21:37:59 +05:00
};
/** @brief nntp credential db using hashed+salted passwords */
class HashedCredDB : public NNTPCredentialDB, public LineReader
{
public:
bool CheckLogin(const std::string & user, const std::string & passwd);
protected:
2016-10-15 22:53:35 +05:00
void SetStream(std::istream * i);
2016-10-15 21:37:59 +05:00
std::string Hash(const std::string & data, const std::string & salt);
2016-10-15 22:53:35 +05:00
void HandleLine(const std::string & line);
2016-10-15 21:37:59 +05:00
private:
bool ProcessLine(const std::string & line);
std::mutex m_access;
std::string m_user, m_passwd;
bool m_found;
/** return true if we have a line that matches this username / password combo */
2016-10-15 22:53:35 +05:00
std::istream * m_instream;
};
class HashedFileDB : public HashedCredDB
{
public:
HashedFileDB(const std::string & fname);
~HashedFileDB();
bool Open();
void Close();
private:
std::string m_fname;
std::ifstream f;
2016-10-15 21:37:59 +05:00
};
}
#endif