Added a new param internal-password-bcrypt-round, set to 12 by default
This commit is contained in:
@@ -35,7 +35,7 @@ namespace lms::db
|
||||
{
|
||||
namespace
|
||||
{
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 75 };
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 76 };
|
||||
}
|
||||
|
||||
VersionInfo::VersionInfo()
|
||||
@@ -962,6 +962,12 @@ SELECT
|
||||
utils::executeCommand(*session.getDboSession(), "DROP INDEX IF EXISTS auth_token_value_idx");
|
||||
}
|
||||
|
||||
void migrateFromV75(Session& session)
|
||||
{
|
||||
// Added a new option to set the bcrypt count to be use to hash user's passwords
|
||||
utils::executeCommand(*session.getDboSession(), "ALTER TABLE user ADD bcrypt_round_count INTEGER NOT NULL DEFAULT(7)");
|
||||
}
|
||||
|
||||
bool doDbMigration(Session& session)
|
||||
{
|
||||
constexpr std::string_view outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
|
||||
@@ -1013,6 +1019,7 @@ SELECT
|
||||
{ 72, migrateFromV72 },
|
||||
{ 73, migrateFromV73 },
|
||||
{ 74, migrateFromV74 },
|
||||
{ 75, migrateFromV75 },
|
||||
};
|
||||
|
||||
bool migrationPerformed{};
|
||||
@@ -1044,7 +1051,9 @@ SELECT
|
||||
LMS_LOG(DB, INFO, "Migrating database from version " << version << " to " << version + 1 << "...");
|
||||
|
||||
auto itMigrationFunc{ migrationFunctions.find(version) };
|
||||
assert(itMigrationFunc != std::cend(migrationFunctions));
|
||||
if (itMigrationFunc == std::cend(migrationFunctions))
|
||||
throw core::LmsException{ "No code found to upgrade database!" };
|
||||
|
||||
itMigrationFunc->second(session);
|
||||
|
||||
VersionInfo::get(session).modify()->setVersion(++version);
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace lms::db
|
||||
public:
|
||||
struct PasswordHash
|
||||
{
|
||||
std::size_t bcryptRoundCount;
|
||||
std::string salt;
|
||||
std::string hash;
|
||||
};
|
||||
@@ -91,7 +92,7 @@ namespace lms::db
|
||||
|
||||
// accessors
|
||||
const std::string& getLoginName() const { return _loginName; }
|
||||
PasswordHash getPasswordHash() const { return PasswordHash{ _passwordSalt, _passwordHash }; }
|
||||
PasswordHash getPasswordHash() const { return PasswordHash{ .bcryptRoundCount = static_cast<std::size_t>(_bcryptRoundCount), .salt = _passwordSalt, .hash = _passwordHash }; }
|
||||
const Wt::WDateTime& getLastLogin() const { return _lastLogin; }
|
||||
std::size_t getAuthTokensCount() const { return _authTokens.size(); }
|
||||
|
||||
@@ -99,6 +100,7 @@ namespace lms::db
|
||||
void setLastLogin(const Wt::WDateTime& dateTime) { _lastLogin = dateTime; }
|
||||
void setPasswordHash(const PasswordHash& passwordHash)
|
||||
{
|
||||
_bcryptRoundCount = passwordHash.bcryptRoundCount;
|
||||
_passwordSalt = passwordHash.salt;
|
||||
_passwordHash = passwordHash.hash;
|
||||
}
|
||||
@@ -132,6 +134,7 @@ namespace lms::db
|
||||
{
|
||||
Wt::Dbo::field(a, _type, "type");
|
||||
Wt::Dbo::field(a, _loginName, "login_name");
|
||||
Wt::Dbo::field(a, _bcryptRoundCount, "bcrypt_round_count");
|
||||
Wt::Dbo::field(a, _passwordSalt, "password_salt");
|
||||
Wt::Dbo::field(a, _passwordHash, "password_hash");
|
||||
Wt::Dbo::field(a, _lastLogin, "last_login");
|
||||
@@ -155,6 +158,7 @@ namespace lms::db
|
||||
static pointer create(Session& session, std::string_view loginName);
|
||||
|
||||
std::string _loginName;
|
||||
int _bcryptRoundCount{};
|
||||
std::string _passwordSalt;
|
||||
std::string _passwordHash;
|
||||
Wt::WDateTime _lastLogin;
|
||||
|
||||
Reference in New Issue
Block a user