diff --git a/src/Makefile.am b/src/Makefile.am index ef7b2d8e..3480f1fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,8 +7,10 @@ lms_SOURCES = \ $(srcdir)/api/subsonic/SubsonicResource.hpp \ $(srcdir)/api/subsonic/SubsonicResponse.cpp \ $(srcdir)/api/subsonic/SubsonicResponse.hpp \ - $(srcdir)/auth/AuthService.cpp \ - $(srcdir)/auth/AuthService.hpp \ + $(srcdir)/auth/AuthTokenService.cpp \ + $(srcdir)/auth/AuthTokenService.hpp \ + $(srcdir)/auth/PasswordService.cpp \ + $(srcdir)/auth/PasswordService.hpp \ $(srcdir)/auth/LoginThrottler.cpp \ $(srcdir)/auth/LoginThrottler.hpp \ $(srcdir)/av/AvInfo.cpp \ diff --git a/src/api/subsonic/SubsonicResource.cpp b/src/api/subsonic/SubsonicResource.cpp index 07028201..6e6939b0 100644 --- a/src/api/subsonic/SubsonicResource.cpp +++ b/src/api/subsonic/SubsonicResource.cpp @@ -26,7 +26,7 @@ #include -#include "auth/AuthService.hpp" +#include "auth/PasswordService.hpp" #include "av/AvTranscoder.hpp" #include "cover/CoverArtGrabber.hpp" #include "database/Artist.hpp" @@ -406,15 +406,15 @@ SubsonicResource::handleRequest(const Wt::Http::Request &request, Wt::Http::Resp const ClientInfo clientInfo {getClientInfo(parameters)}; - switch (getService()->checkUserPassword(dbSession, + switch (getService()->checkUserPassword(dbSession, boost::asio::ip::address::from_string(request.clientAddress()), clientInfo.user, clientInfo.password)) { - case Auth::AuthService::PasswordCheckResult::Match: + case Auth::PasswordService::PasswordCheckResult::Match: break; - case Auth::AuthService::PasswordCheckResult::Mismatch: + case Auth::PasswordService::PasswordCheckResult::Mismatch: throw Error {Error::Code::WrongUsernameOrPassword}; - case Auth::AuthService::PasswordCheckResult::Throttled: + case Auth::PasswordService::PasswordCheckResult::Throttled: throw Error {Error::CustomType::LoginThrottled}; } diff --git a/src/auth/AuthService.cpp b/src/auth/AuthService.cpp deleted file mode 100644 index c91795a9..00000000 --- a/src/auth/AuthService.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (C) 2019 Emeric Poupon - * - * This file is part of LMS. - * - * LMS is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LMS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LMS. If not, see . - */ - -/* This file contains some classes in order to get info from file using the libavconv */ - -#include "AuthService.hpp" - -#include -#include -#include - -#include "database/Session.hpp" -#include "utils/Exception.hpp" -#include "utils/Utils.hpp" -#include "utils/Logger.hpp" - -namespace Auth { - -AuthService::AuthService(std::size_t maxThrottlerEntries) -: _passwordLoginThrottler {maxThrottlerEntries} -, _tokenLoginThrottler {maxThrottlerEntries} -{ -} - -static -bool -checkUserPassword(Database::Session& session, const std::string& loginName, const std::string& password) -{ - Database::User::PasswordHash passwordHash; - { - auto transaction {session.createSharedTransaction()}; - - const Database::User::pointer user {Database::User::getByLoginName(session, loginName)}; - if (!user) - return false; - - passwordHash = user->getPasswordHash(); - } - - const Wt::Auth::BCryptHashFunction hashFunc {6}; - return hashFunc.verify(password, passwordHash.salt, passwordHash.hash); -} - - -AuthService::PasswordCheckResult -AuthService::checkUserPassword(Database::Session& session, const boost::asio::ip::address& clientAddress, const std::string& loginName, const std::string& password) -{ - // Do not waste too much resource on brute force attacks (optim) - { - std::shared_lock lock {_passwordCheckMutex}; - - if (_passwordLoginThrottler.isClientThrottled(clientAddress)) - return PasswordCheckResult::Throttled; - } - - const bool match {Auth::checkUserPassword(session, loginName, password)}; - { - std::unique_lock lock {_passwordCheckMutex}; - - if (_passwordLoginThrottler.isClientThrottled(clientAddress)) - return PasswordCheckResult::Throttled; - - if (match) - { - _passwordLoginThrottler.onGoodClientAttempt(clientAddress); - return PasswordCheckResult::Match; - } - else - { - _passwordLoginThrottler.onBadClientAttempt(clientAddress); - return PasswordCheckResult::Mismatch; - } - } -} - -Database::User::PasswordHash -AuthService::hashPassword(const std::string& password) const -{ - const std::string salt {Wt::WRandom::generateId(32)}; - - const Wt::Auth::BCryptHashFunction hashFunc {6}; - return {salt, hashFunc.compute(password, salt)}; -} - -bool -AuthService::evaluatePasswordStrength(const std::string& loginName, const std::string& password) const -{ - Wt::Auth::PasswordStrengthValidator validator; - validator.setMinimumLength(Wt::Auth::PasswordStrengthType::OneCharClass, 4); - validator.setMinimumLength(Wt::Auth::PasswordStrengthType::TwoCharClass, 4); - validator.setMinimumLength(Wt::Auth::PasswordStrengthType::PassPhrase, 4); - validator.setMinimumLength(Wt::Auth::PasswordStrengthType::ThreeCharClass, 4); - validator.setMinimumLength(Wt::Auth::PasswordStrengthType::FourCharClass, 4); - validator.setMinimumPassPhraseWords(1); - validator.setMinimumMatchLength(3); - - return validator.evaluateStrength(password, loginName, "").isValid(); -} - - -std::string -AuthService::createAuthToken(Database::Session& session, Database::IdType userId, const Wt::WDateTime& expiry) -{ - const std::string secret {Wt::WRandom::generateId(64)}; - - auto transaction {session.createUniqueTransaction()}; - - Database::User::pointer user {Database::User::getById(session, userId)}; - if (!user) - throw LmsException {"User deleted"}; - - Database::AuthToken::pointer authToken {Database::AuthToken::create(session, secret, expiry, user)}; - - LMS_LOG(UI, DEBUG) << "Created auth token for user '" << user->getLoginName() << "', expiry = " << expiry.toString(); - - if (user->getAuthTokensCount() >= 50) - Database::AuthToken::removeExpiredTokens(session, Wt::WDateTime::currentDateTime()); - - return secret; -} - -static -boost::optional -processAuthToken(Database::Session& session, const std::string& tokenValue) -{ - auto transaction {session.createUniqueTransaction()}; - - Database::AuthToken::pointer authToken {Database::AuthToken::getByValue(session, tokenValue)}; - if (!authToken) - return boost::none; - - if (authToken->getExpiry() < Wt::WDateTime::currentDateTime()) - { - authToken.remove(); - return boost::none; - } - - LMS_LOG(UI, DEBUG) << "Found auth token for user '" << authToken->getUser()->getLoginName() << "'!"; - - AuthService::AuthTokenProcessResult::AuthTokenInfo res {authToken->getUser().id(), authToken->getExpiry()}; - authToken.remove(); - - return res; -} - - -AuthService::AuthTokenProcessResult -AuthService::processAuthToken(Database::Session& session, const boost::asio::ip::address& clientAddress, const std::string& tokenValue) -{ - // Do not waste too much resource on brute force attacks (optim) - { - std::shared_lock lock {_tokenCheckMutex}; - - if (_tokenLoginThrottler.isClientThrottled(clientAddress)) - return AuthTokenProcessResult {AuthTokenProcessResult::State::Throttled}; - } - - auto res {Auth::processAuthToken(session, tokenValue)}; - { - std::unique_lock lock {_tokenCheckMutex}; - - if (_tokenLoginThrottler.isClientThrottled(clientAddress)) - return AuthTokenProcessResult {AuthTokenProcessResult::State::Throttled}; - - if (!res) - { - _tokenLoginThrottler.onBadClientAttempt(clientAddress); - return AuthTokenProcessResult {AuthTokenProcessResult::State::NotFound}; - } - - _tokenLoginThrottler.onGoodClientAttempt(clientAddress); - return AuthTokenProcessResult {AuthTokenProcessResult::State::Found, std::move(*res)}; - } -} - - -} // namespace Auth - diff --git a/src/auth/AuthTokenService.cpp b/src/auth/AuthTokenService.cpp new file mode 100644 index 00000000..aa629777 --- /dev/null +++ b/src/auth/AuthTokenService.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2019 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +/* This file contains some classes in order to get info from file using the libavconv */ + +#include "AuthTokenService.hpp" + +#include +#include +#include + +#include "database/Session.hpp" +#include "utils/Exception.hpp" +#include "utils/Utils.hpp" +#include "utils/Logger.hpp" + +namespace Auth { + +AuthTokenService::AuthTokenService(std::size_t maxThrottlerEntries) +: _loginThrottler {maxThrottlerEntries} +{ +} + +std::string +AuthTokenService::createAuthToken(Database::Session& session, Database::IdType userId, const Wt::WDateTime& expiry) +{ + const std::string secret {Wt::WRandom::generateId(64)}; + + auto transaction {session.createUniqueTransaction()}; + + Database::User::pointer user {Database::User::getById(session, userId)}; + if (!user) + throw LmsException {"User deleted"}; + + Database::AuthToken::pointer authToken {Database::AuthToken::create(session, secret, expiry, user)}; + + LMS_LOG(UI, DEBUG) << "Created auth token for user '" << user->getLoginName() << "', expiry = " << expiry.toString(); + + if (user->getAuthTokensCount() >= 50) + Database::AuthToken::removeExpiredTokens(session, Wt::WDateTime::currentDateTime()); + + return secret; +} + +static +boost::optional +processAuthToken(Database::Session& session, const std::string& tokenValue) +{ + auto transaction {session.createUniqueTransaction()}; + + Database::AuthToken::pointer authToken {Database::AuthToken::getByValue(session, tokenValue)}; + if (!authToken) + return boost::none; + + if (authToken->getExpiry() < Wt::WDateTime::currentDateTime()) + { + authToken.remove(); + return boost::none; + } + + LMS_LOG(UI, DEBUG) << "Found auth token for user '" << authToken->getUser()->getLoginName() << "'!"; + + AuthTokenService::AuthTokenProcessResult::AuthTokenInfo res {authToken->getUser().id(), authToken->getExpiry()}; + authToken.remove(); + + return res; +} + + +AuthTokenService::AuthTokenProcessResult +AuthTokenService::processAuthToken(Database::Session& session, const boost::asio::ip::address& clientAddress, const std::string& tokenValue) +{ + // Do not waste too much resource on brute force attacks (optim) + { + std::shared_lock lock {_mutex}; + + if (_loginThrottler.isClientThrottled(clientAddress)) + return AuthTokenProcessResult {AuthTokenProcessResult::State::Throttled}; + } + + auto res {Auth::processAuthToken(session, tokenValue)}; + { + std::unique_lock lock {_mutex}; + + if (_loginThrottler.isClientThrottled(clientAddress)) + return AuthTokenProcessResult {AuthTokenProcessResult::State::Throttled}; + + if (!res) + { + _loginThrottler.onBadClientAttempt(clientAddress); + return AuthTokenProcessResult {AuthTokenProcessResult::State::NotFound}; + } + + _loginThrottler.onGoodClientAttempt(clientAddress); + return AuthTokenProcessResult {AuthTokenProcessResult::State::Found, std::move(*res)}; + } +} + + +} // namespace Auth + diff --git a/src/auth/AuthTokenService.hpp b/src/auth/AuthTokenService.hpp new file mode 100644 index 00000000..fd8dc7ab --- /dev/null +++ b/src/auth/AuthTokenService.hpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2019 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +/* This file contains some classes in order to get info from file using the libavconv */ + +#pragma once + +#include + +#include +#include + +#include "LoginThrottler.hpp" +#include "database/User.hpp" +#include "database/Types.hpp" + +namespace Database +{ + class Session; +} + + +namespace Auth { + + class AuthTokenService + { + public: + + AuthTokenService(std::size_t maxThrottlerEntries); + + AuthTokenService() = default; + ~AuthTokenService() = default; + + AuthTokenService(const AuthTokenService&) = delete; + AuthTokenService& operator=(const AuthTokenService&) = delete; + AuthTokenService(AuthTokenService&&) = delete; + AuthTokenService& operator=(AuthTokenService&&) = delete; + + + // Auth Token services + struct AuthTokenProcessResult + { + enum class State + { + Found, + Throttled, + NotFound, + }; + + struct AuthTokenInfo + { + Database::IdType userId; + Wt::WDateTime expiry; + }; + + State state; + boost::optional authTokenInfo; + }; + + // Removed if found + AuthTokenProcessResult processAuthToken(Database::Session& session, const boost::asio::ip::address& clientAddress, const std::string& tokenValue); + std::string createAuthToken(Database::Session& session, Database::IdType userid, const Wt::WDateTime& expiry); + + private: + + std::shared_timed_mutex _mutex; + LoginThrottler _loginThrottler; + }; + +} + diff --git a/src/auth/PasswordService.cpp b/src/auth/PasswordService.cpp new file mode 100644 index 00000000..383c667d --- /dev/null +++ b/src/auth/PasswordService.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2019 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +/* This file contains some classes in order to get info from file using the libavconv */ + +#include "PasswordService.hpp" + +#include +#include +#include + +#include "database/Session.hpp" +#include "utils/Exception.hpp" +#include "utils/Utils.hpp" +#include "utils/Logger.hpp" + +namespace Auth { + +PasswordService::PasswordService(std::size_t maxThrottlerEntries) +: _loginThrottler{maxThrottlerEntries} +{ +} + +static +bool +checkUserPassword(Database::Session& session, const std::string& loginName, const std::string& password) +{ + Database::User::PasswordHash passwordHash; + { + auto transaction {session.createSharedTransaction()}; + + const Database::User::pointer user {Database::User::getByLoginName(session, loginName)}; + if (!user) + return false; + + passwordHash = user->getPasswordHash(); + } + + const Wt::Auth::BCryptHashFunction hashFunc {6}; + return hashFunc.verify(password, passwordHash.salt, passwordHash.hash); +} + + +PasswordService::PasswordCheckResult +PasswordService::checkUserPassword(Database::Session& session, const boost::asio::ip::address& clientAddress, const std::string& loginName, const std::string& password) +{ + // Do not waste too much resource on brute force attacks (optim) + { + std::shared_lock lock {_mutex}; + + if (_loginThrottler.isClientThrottled(clientAddress)) + return PasswordCheckResult::Throttled; + } + + const bool match {Auth::checkUserPassword(session, loginName, password)}; + { + std::unique_lock lock {_mutex}; + + if (_loginThrottler.isClientThrottled(clientAddress)) + return PasswordCheckResult::Throttled; + + if (match) + { + _loginThrottler.onGoodClientAttempt(clientAddress); + return PasswordCheckResult::Match; + } + else + { + _loginThrottler.onBadClientAttempt(clientAddress); + return PasswordCheckResult::Mismatch; + } + } +} + +Database::User::PasswordHash +PasswordService::hashPassword(const std::string& password) const +{ + const std::string salt {Wt::WRandom::generateId(32)}; + + const Wt::Auth::BCryptHashFunction hashFunc {6}; + return {salt, hashFunc.compute(password, salt)}; +} + +bool +PasswordService::evaluatePasswordStrength(const std::string& loginName, const std::string& password) const +{ + Wt::Auth::PasswordStrengthValidator validator; + validator.setMinimumLength(Wt::Auth::PasswordStrengthType::OneCharClass, 4); + validator.setMinimumLength(Wt::Auth::PasswordStrengthType::TwoCharClass, 4); + validator.setMinimumLength(Wt::Auth::PasswordStrengthType::PassPhrase, 4); + validator.setMinimumLength(Wt::Auth::PasswordStrengthType::ThreeCharClass, 4); + validator.setMinimumLength(Wt::Auth::PasswordStrengthType::FourCharClass, 4); + validator.setMinimumPassPhraseWords(1); + validator.setMinimumMatchLength(3); + + return validator.evaluateStrength(password, loginName, "").isValid(); +} + +} // namespace Auth + diff --git a/src/auth/AuthService.hpp b/src/auth/PasswordService.hpp similarity index 81% rename from src/auth/AuthService.hpp rename to src/auth/PasswordService.hpp index 4968d64c..e7d479d6 100644 --- a/src/auth/AuthService.hpp +++ b/src/auth/PasswordService.hpp @@ -38,19 +38,19 @@ namespace Database namespace Auth { - class AuthService + class PasswordService { public: - AuthService(std::size_t maxThrottlerEntries); + PasswordService(std::size_t maxThrottlerEntries); - AuthService() = default; - ~AuthService() = default; + PasswordService() = default; + ~PasswordService() = default; - AuthService(const AuthService&) = delete; - AuthService& operator=(const AuthService&) = delete; - AuthService(AuthService&&) = delete; - AuthService& operator=(AuthService&&) = delete; + PasswordService(const PasswordService&) = delete; + PasswordService& operator=(const PasswordService&) = delete; + PasswordService(PasswordService&&) = delete; + PasswordService& operator=(PasswordService&&) = delete; // Password services @@ -90,11 +90,8 @@ namespace Auth { private: - std::shared_timed_mutex _passwordCheckMutex; - std::shared_timed_mutex _tokenCheckMutex; - - LoginThrottler _passwordLoginThrottler; - LoginThrottler _tokenLoginThrottler; + std::shared_timed_mutex _mutex; + LoginThrottler _loginThrottler; }; } diff --git a/src/main/main.cpp b/src/main/main.cpp index 338206fa..3da52578 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -26,7 +26,8 @@ #include "api/subsonic/SubsonicResource.hpp" #include "av/AvInfo.hpp" #include "av/AvTranscoder.hpp" -#include "auth/AuthService.hpp" +#include "auth/AuthTokenService.hpp" +#include "auth/PasswordService.hpp" #include "cover/CoverArtGrabber.hpp" #include "image/Image.hpp" #include "scanner/MediaScanner.hpp" @@ -129,7 +130,8 @@ int main(int argc, char* argv[]) UserInterface::LmsApplicationGroupContainer appGroups; // Service initialization order is important - ServiceProvider::create(getService()->getULong("login-throttler-max-entriees", 10000)); + ServiceProvider::create(getService()->getULong("login-throttler-max-entriees", 10000)); + ServiceProvider::create(getService()->getULong("login-throttler-max-entriees", 10000)); Scanner::MediaScanner& mediaScanner {ServiceProvider::create(database.createSession())}; Similarity::FeaturesScannerAddon similarityFeaturesScannerAddon {database.createSession()}; diff --git a/src/ui/Auth.cpp b/src/ui/Auth.cpp index 910670ad..0897f8c8 100644 --- a/src/ui/Auth.cpp +++ b/src/ui/Auth.cpp @@ -27,7 +27,8 @@ #include #include -#include "auth/AuthService.hpp" +#include "auth/AuthTokenService.hpp" +#include "auth/PasswordService.hpp" #include "main/Service.hpp" #include "utils/Logger.hpp" @@ -42,7 +43,7 @@ static void createAuthToken(Database::IdType userId, const Wt::WDateTime& expiry) { - const std::string secret {getService<::Auth::AuthService>()->createAuthToken(LmsApp->getDbSession(), userId, expiry)}; + const std::string secret {getService<::Auth::AuthTokenService>()->createAuthToken(LmsApp->getDbSession(), userId, expiry)}; LmsApp->setCookie(authCookieName, secret, @@ -60,15 +61,15 @@ processAuthToken(const Wt::WEnvironment& env) if (!authCookie) return boost::none; - const auto res {getService<::Auth::AuthService>()->processAuthToken(LmsApp->getDbSession(), boost::asio::ip::address::from_string(env.clientAddress()), *authCookie)}; + const auto res {getService<::Auth::AuthTokenService>()->processAuthToken(LmsApp->getDbSession(), boost::asio::ip::address::from_string(env.clientAddress()), *authCookie)}; switch (res.state) { - case ::Auth::AuthService::AuthTokenProcessResult::State::NotFound: - case ::Auth::AuthService::AuthTokenProcessResult::State::Throttled: + case ::Auth::AuthTokenService::AuthTokenProcessResult::State::NotFound: + case ::Auth::AuthTokenService::AuthTokenProcessResult::State::Throttled: LmsApp->setCookie(authCookieName, std::string {}, 0, "", "", env.urlScheme() == "https"); return boost::none; - case ::Auth::AuthService::AuthTokenProcessResult::State::Found: + case ::Auth::AuthTokenService::AuthTokenProcessResult::State::Found: createAuthToken(res.authTokenInfo->userId, res.authTokenInfo->expiry); break; } @@ -124,18 +125,18 @@ class AuthModel : public Wt::WFormModel if (field == PasswordField) { - switch (getService<::Auth::AuthService>()->checkUserPassword( + switch (getService<::Auth::PasswordService>()->checkUserPassword( LmsApp->getDbSession(), boost::asio::ip::address::from_string(LmsApp->environment().clientAddress()), valueText(LoginNameField).toUTF8(), valueText(PasswordField).toUTF8())) { - case ::Auth::AuthService::PasswordCheckResult::Match: + case ::Auth::PasswordService::PasswordCheckResult::Match: break; - case ::Auth::AuthService::PasswordCheckResult::Mismatch: + case ::Auth::PasswordService::PasswordCheckResult::Mismatch: error = Wt::WString::tr("Lms.password-bad-login-combination"); break; - case ::Auth::AuthService::PasswordCheckResult::Throttled: + case ::Auth::PasswordService::PasswordCheckResult::Throttled: error = Wt::WString::tr("Lms.password-client-throttled"); break; } diff --git a/src/ui/SettingsView.cpp b/src/ui/SettingsView.cpp index baec3f3a..fc92f780 100644 --- a/src/ui/SettingsView.cpp +++ b/src/ui/SettingsView.cpp @@ -31,7 +31,7 @@ #include "common/Validators.hpp" #include "common/ValueStringModel.hpp" -#include "auth/AuthService.hpp" +#include "auth/PasswordService.hpp" #include "main/Service.hpp" #include "utils/Logger.hpp" #include "LmsApplication.hpp" @@ -75,7 +75,7 @@ class SettingsModel : public Wt::WFormModel Database::User::PasswordHash passwordHash; if (!valueText(PasswordField).empty()) - passwordHash = getService<::Auth::AuthService>()->hashPassword(valueText(PasswordField).toUTF8()); + passwordHash = getService<::Auth::PasswordService>()->hashPassword(valueText(PasswordField).toUTF8()); auto transaction {LmsApp->getDbSession().createUniqueTransaction()}; @@ -125,7 +125,7 @@ class SettingsModel : public Wt::WFormModel { if (!valueText(PasswordField).empty()) { - if (!getService<::Auth::AuthService>()->evaluatePasswordStrength(LmsApp->getUserLoginName(), valueText(PasswordField).toUTF8())) + if (!getService<::Auth::PasswordService>()->evaluatePasswordStrength(LmsApp->getUserLoginName(), valueText(PasswordField).toUTF8())) error = Wt::WString::tr("Lms.password-too-weak"); } else diff --git a/src/ui/admin/InitWizardView.cpp b/src/ui/admin/InitWizardView.cpp index 21cb5d20..50168110 100644 --- a/src/ui/admin/InitWizardView.cpp +++ b/src/ui/admin/InitWizardView.cpp @@ -23,7 +23,7 @@ #include #include -#include "auth/AuthService.hpp" +#include "auth/PasswordService.hpp" #include "main/Service.hpp" #include "utils/Exception.hpp" #include "utils/Logger.hpp" @@ -55,7 +55,7 @@ class InitWizardModel : public Wt::WFormModel void saveData() { - const Database::User::PasswordHash passwordHash {getService<::Auth::AuthService>()->hashPassword(valueText(PasswordField).toUTF8())}; + const Database::User::PasswordHash passwordHash {getService<::Auth::PasswordService>()->hashPassword(valueText(PasswordField).toUTF8())}; auto transaction(LmsApp->getDbSession().createUniqueTransaction()); @@ -77,7 +77,7 @@ class InitWizardModel : public Wt::WFormModel if (!valueText(PasswordField).empty()) { // Evaluate the strength of the password - if (!getService<::Auth::AuthService>()->evaluatePasswordStrength(valueText(AdminLoginField).toUTF8(), valueText(PasswordField).toUTF8())) + if (!getService<::Auth::PasswordService>()->evaluatePasswordStrength(valueText(AdminLoginField).toUTF8(), valueText(PasswordField).toUTF8())) error = Wt::WString::tr("Lms.password-too-weak"); } else diff --git a/src/ui/admin/UserView.cpp b/src/ui/admin/UserView.cpp index 3ee13943..9ace8c53 100644 --- a/src/ui/admin/UserView.cpp +++ b/src/ui/admin/UserView.cpp @@ -28,7 +28,7 @@ #include -#include "auth/AuthService.hpp" +#include "auth/PasswordService.hpp" #include "database/User.hpp" #include "main/Service.hpp" #include "utils/Config.hpp" @@ -82,7 +82,7 @@ class UserModel : public Wt::WFormModel { boost::optional passwordHash; if (!valueText(PasswordField).empty()) - passwordHash = getService<::Auth::AuthService>()->hashPassword(valueText(PasswordField).toUTF8()); + passwordHash = getService<::Auth::PasswordService>()->hashPassword(valueText(PasswordField).toUTF8()); auto transaction {LmsApp->getDbSession().createUniqueTransaction()}; @@ -172,7 +172,7 @@ class UserModel : public Wt::WFormModel else { // Evaluate the strength of the password for non demo accounts - if (!getService<::Auth::AuthService>()->evaluatePasswordStrength(getLoginName(), valueText(PasswordField).toUTF8())) + if (!getService<::Auth::PasswordService>()->evaluatePasswordStrength(getLoginName(), valueText(PasswordField).toUTF8())) error = Wt::WString::tr("Lms.password-too-weak"); } }