mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 09:04:53 -07:00
Almost completed registration
* added missing bits of serverside code; * added fronted in client; * removed demo python scripts;
This commit is contained in:
parent
735fcbf311
commit
5ace0dd892
20 changed files with 585 additions and 112 deletions
|
|
@ -8,6 +8,8 @@
|
|||
#include <QCryptographicHash>
|
||||
#endif
|
||||
|
||||
#include "rng_sfmt.h"
|
||||
|
||||
void PasswordHasher::initialize()
|
||||
{
|
||||
#if QT_VERSION < 0x050000
|
||||
|
|
@ -51,3 +53,20 @@ QString PasswordHasher::computeHash(const QString &password, const QString &salt
|
|||
return hashedPass;
|
||||
}
|
||||
#endif
|
||||
|
||||
QString PasswordHasher::generateRandomSalt(const int len)
|
||||
{
|
||||
static const char alphanum[] =
|
||||
"0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
QString ret;
|
||||
int size = sizeof(alphanum) - 1;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
ret.append(alphanum[rng->rand(0, size)]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class PasswordHasher {
|
|||
public:
|
||||
static void initialize();
|
||||
static QString computeHash(const QString &password, const QString &salt);
|
||||
static QString generateRandomSalt(const int len = 16);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -130,7 +130,6 @@ bool Servatrice_DatabaseInterface::registerUser(const QString &userName, const Q
|
|||
|
||||
if (!execSqlQuery(query)) {
|
||||
qDebug() << "Failed to insert user: " << query->lastError() << " sql: " << query->lastQuery();
|
||||
// TODO handle duplicate insert error
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +171,6 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
|
|||
if (checkUserIsBanned(handler->getAddress(), user, reasonStr, banSecondsLeft))
|
||||
return UserIsBanned;
|
||||
|
||||
QSqlQuery *passwordQuery = prepareQuery("select password_sha512 from {prefix}_users where name = :name and active = 1");
|
||||
passwordQuery->bindValue(":name", user);
|
||||
if (!execSqlQuery(passwordQuery)) {
|
||||
qDebug("Login denied: SQL error");
|
||||
|
|
@ -270,7 +268,6 @@ bool Servatrice_DatabaseInterface::checkUserIsIpBanned(const QString &ipAddress,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Servatrice_DatabaseInterface::userExists(const QString &user)
|
||||
{
|
||||
if (server->getAuthenticationMethod() == Servatrice::AuthenticationSql) {
|
||||
checkSql();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <QObject>
|
||||
#include <QSqlDatabase>
|
||||
#include <QHash>
|
||||
#include <qchar.h>
|
||||
#include <QChar>
|
||||
|
||||
#include "server.h"
|
||||
#include "server_database_interface.h"
|
||||
|
|
@ -41,6 +41,7 @@ public:
|
|||
bool execSqlQuery(QSqlQuery *query);
|
||||
const QSqlDatabase &getDatabase() { return sqlDatabase; }
|
||||
|
||||
bool activeUserExists(const QString &user);
|
||||
bool userExists(const QString &user);
|
||||
int getUserIdInDB(const QString &name);
|
||||
QMap<QString, ServerInfo_User> getBuddyList(const QString &name);
|
||||
|
|
@ -63,7 +64,7 @@ public:
|
|||
bool userSessionExists(const QString &userName);
|
||||
|
||||
bool getRequireRegistration();
|
||||
bool registerUser(const QString &userName, const QString &realName, ServerInfo_User_Gender const &gender, const QString &passwordSha512, const QString &emailAddress, const QString &country, bool active = false);
|
||||
bool registerUser(const QString &userName, const QString &realName, ServerInfo_User_Gender const &gender, const QString &password, const QString &emailAddress, const QString &country, bool active = false);
|
||||
|
||||
void logMessage(const int senderId, const QString &senderName, const QString &senderIp, const QString &logMessage, LogMessage_TargetType targetType, const int targetId, const QString &targetName);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue