Servatrice: added authentication type "password"

This commit is contained in:
Fabio Bas 2014-10-04 17:50:01 +02:00
parent 0261862b1b
commit 0d9eec4b64
3 changed files with 12 additions and 2 deletions

View file

@ -141,9 +141,11 @@ bool Servatrice::initServer()
const QString authenticationMethodStr = settingsCache->value("authentication/method").toString(); const QString authenticationMethodStr = settingsCache->value("authentication/method").toString();
if (authenticationMethodStr == "sql") { if (authenticationMethodStr == "sql") {
authenticationMethod = AuthenticationSql; authenticationMethod = AuthenticationSql;
} else if(authenticationMethodStr == "password") {
authenticationMethod = AuthenticationPassword;
} else { } else {
if (regServerOnly) { if (regServerOnly) {
qDebug() << "Registration only server enabled but no DB Connection : Error."; qDebug() << "Registration only server enabled but no authentication method defined: Error.";
return false; return false;
} }
authenticationMethod = AuthenticationNone; authenticationMethod = AuthenticationNone;

View file

@ -88,7 +88,7 @@ class Servatrice : public Server
{ {
Q_OBJECT Q_OBJECT
public: public:
enum AuthenticationMethod { AuthenticationNone, AuthenticationSql }; enum AuthenticationMethod { AuthenticationNone, AuthenticationSql, AuthenticationPassword };
private slots: private slots:
void statusUpdate(); void statusUpdate();
void shutdownTimeout(); void shutdownTimeout();

View file

@ -2,6 +2,7 @@
#include "servatrice_database_interface.h" #include "servatrice_database_interface.h"
#include "passwordhasher.h" #include "passwordhasher.h"
#include "serversocketinterface.h" #include "serversocketinterface.h"
#include "settingscache.h"
#include "decklist.h" #include "decklist.h"
#include "pb/game_replay.pb.h" #include "pb/game_replay.pb.h"
#include <QDebug> #include <QDebug>
@ -92,6 +93,13 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
{ {
switch (server->getAuthenticationMethod()) { switch (server->getAuthenticationMethod()) {
case Servatrice::AuthenticationNone: return UnknownUser; case Servatrice::AuthenticationNone: return UnknownUser;
case Servatrice::AuthenticationPassword: {
QString configPassword = settingsCache->value("authentication/password").toString();
if(configPassword == password)
return PasswordRight;
return NotLoggedIn;
}
case Servatrice::AuthenticationSql: { case Servatrice::AuthenticationSql: {
if (!checkSql()) if (!checkSql())
return UnknownUser; return UnknownUser;