login consistency fix; limit length of user names to 35
This commit is contained in:
parent
a4552a1596
commit
102e246c6d
5 changed files with 27 additions and 2 deletions
|
@ -19,6 +19,7 @@ public:
|
||||||
|
|
||||||
LocalServerInterface *newConnection();
|
LocalServerInterface *newConnection();
|
||||||
protected:
|
protected:
|
||||||
|
bool userExists(const QString & /*name*/) { return false; }
|
||||||
ServerInfo_User *getUserData(const QString &name);
|
ServerInfo_User *getUserData(const QString &name);
|
||||||
QList<ServerInfo_User *> getBuddyList(const QString & /*name*/) { return QList<ServerInfo_User *>(); }
|
QList<ServerInfo_User *> getBuddyList(const QString & /*name*/) { return QList<ServerInfo_User *>(); }
|
||||||
QList<ServerInfo_User *> getIgnoreList(const QString & /*name*/) { return QList<ServerInfo_User *>(); }
|
QList<ServerInfo_User *> getIgnoreList(const QString & /*name*/) { return QList<ServerInfo_User *>(); }
|
||||||
|
|
|
@ -38,6 +38,8 @@ Server::~Server()
|
||||||
|
|
||||||
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password)
|
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password)
|
||||||
{
|
{
|
||||||
|
if (name.size() > 35)
|
||||||
|
name = name.left(35);
|
||||||
AuthenticationResult authState = checkUserPassword(name, password);
|
AuthenticationResult authState = checkUserPassword(name, password);
|
||||||
if (authState == PasswordWrong)
|
if (authState == PasswordWrong)
|
||||||
return authState;
|
return authState;
|
||||||
|
@ -47,10 +49,11 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
||||||
if (oldSession)
|
if (oldSession)
|
||||||
delete oldSession; // ~Server_ProtocolHandler() will call Server::removeClient
|
delete oldSession; // ~Server_ProtocolHandler() will call Server::removeClient
|
||||||
} else if (authState == UnknownUser) {
|
} else if (authState == UnknownUser) {
|
||||||
// Change user name so that no two users have the same names
|
// Change user name so that no two users have the same names,
|
||||||
|
// don't interfere with registered user names though.
|
||||||
QString tempName = name;
|
QString tempName = name;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (users.contains(tempName))
|
while (users.contains(tempName) || userExists(tempName))
|
||||||
tempName = name + "_" + QString::number(++i);
|
tempName = name + "_" + QString::number(++i);
|
||||||
name = tempName;
|
name = tempName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ protected:
|
||||||
QMap<QString, Server_ProtocolHandler *> users;
|
QMap<QString, Server_ProtocolHandler *> users;
|
||||||
QMap<int, Server_Room *> rooms;
|
QMap<int, Server_Room *> rooms;
|
||||||
|
|
||||||
|
virtual bool userExists(const QString &user) = 0;
|
||||||
virtual AuthenticationResult checkUserPassword(const QString &user, const QString &password) = 0;
|
virtual AuthenticationResult checkUserPassword(const QString &user, const QString &password) = 0;
|
||||||
virtual ServerInfo_User *getUserData(const QString &name) = 0;
|
virtual ServerInfo_User *getUserData(const QString &name) = 0;
|
||||||
int nextGameId;
|
int nextGameId;
|
||||||
|
|
|
@ -170,6 +170,25 @@ AuthenticationResult Servatrice::checkUserPassword(const QString &user, const QS
|
||||||
return UnknownUser;
|
return UnknownUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Servatrice::userExists(const QString &user)
|
||||||
|
{
|
||||||
|
const QString method = settings->value("authentication/method").toString();
|
||||||
|
if (method == "sql") {
|
||||||
|
checkSql();
|
||||||
|
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("select 1 from " + dbPrefix + "_users where name = :name");
|
||||||
|
query.bindValue(":name", user);
|
||||||
|
qDebug() << "a";
|
||||||
|
if (!execSqlQuery(query))
|
||||||
|
return false;
|
||||||
|
qDebug() << "b";
|
||||||
|
bool res = query.next();
|
||||||
|
qDebug() << res << user;
|
||||||
|
return res;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
ServerInfo_User *Servatrice::evalUserQueryResult(const QSqlQuery &query, bool complete)
|
ServerInfo_User *Servatrice::evalUserQueryResult(const QSqlQuery &query, bool complete)
|
||||||
{
|
{
|
||||||
QString name = query.value(0).toString();
|
QString name = query.value(0).toString();
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
QString getDbPrefix() const { return dbPrefix; }
|
QString getDbPrefix() const { return dbPrefix; }
|
||||||
void updateLoginMessage();
|
void updateLoginMessage();
|
||||||
protected:
|
protected:
|
||||||
|
bool userExists(const QString &user);
|
||||||
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
||||||
ServerInfo_User *getUserData(const QString &name);
|
ServerInfo_User *getUserData(const QString &name);
|
||||||
QList<ServerInfo_User *> getBuddyList(const QString &name);
|
QList<ServerInfo_User *> getBuddyList(const QString &name);
|
||||||
|
|
Loading…
Reference in a new issue