X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fsqlitestorage.cpp;h=46e2c70e981b580bb798660c6a5fad4852a1792d;hp=311b47f772f1fc88d684c21f884551b36f7b9006;hb=9a440b6a972595bc556f34504cdbb3ea56ca53fd;hpb=84cd3561e97167ffb98ecab0fd2b884ba1d13ada diff --git a/src/core/sqlitestorage.cpp b/src/core/sqlitestorage.cpp index 311b47f7..46e2c70e 100644 --- a/src/core/sqlitestorage.cpp +++ b/src/core/sqlitestorage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2015 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -129,7 +129,8 @@ UserId SqliteStorage::addUser(const QString &user, const QString &password) QSqlQuery query(db); query.prepare(queryString("insert_quasseluser")); query.bindValue(":username", user); - query.bindValue(":password", cryptedPassword(password)); + query.bindValue(":password", hashPassword(password)); + query.bindValue(":hashversion", Storage::HashVersion::Latest); lockForWrite(); safeExec(query); if (query.lastError().isValid() && query.lastError().number() == 19) { // user already exists - sadly 19 seems to be the general constraint violation error... @@ -158,7 +159,8 @@ bool SqliteStorage::updateUser(UserId user, const QString &password) QSqlQuery query(db); query.prepare(queryString("update_userpassword")); query.bindValue(":userid", user.toInt()); - query.bindValue(":password", cryptedPassword(password)); + query.bindValue(":password", hashPassword(password)); + query.bindValue(":hashversion", Storage::HashVersion::Latest); lockForWrite(); safeExec(query); success = query.numRowsAffected() != 0; @@ -190,23 +192,30 @@ void SqliteStorage::renameUser(UserId user, const QString &newName) UserId SqliteStorage::validateUser(const QString &user, const QString &password) { UserId userId; + QString hashedPassword; + Storage::HashVersion hashVersion; { QSqlQuery query(logDb()); query.prepare(queryString("select_authuser")); query.bindValue(":username", user); - query.bindValue(":password", cryptedPassword(password)); lockForRead(); safeExec(query); if (query.first()) { userId = query.value(0).toInt(); + hashedPassword = query.value(1).toString(); + hashVersion = static_cast(query.value(2).toInt()); } } unlock(); - return userId; + UserId returnUserId; + if (userId != 0 && checkHashedPassword(userId, password, hashedPassword, hashVersion)) { + returnUserId = userId; + } + return returnUserId; }