Fixed demo account creation. fixes #167

This commit is contained in:
emeric
2021-09-02 21:05:13 +02:00
parent 9e37012090
commit 56a588a06b
19 changed files with 172 additions and 162 deletions
@@ -81,9 +81,18 @@ namespace Auth
}
bool
InternalPasswordService::isPasswordSecureEnough(std::string_view loginName, std::string_view password) const
InternalPasswordService::isPasswordSecureEnough(std::string_view password, const PasswordValidationContext& context) const
{
return _validator.evaluateStrength(std::string {password}, std::string {loginName}, "").isValid();
switch (context.userType)
{
case Database::UserType::ADMIN:
case Database::UserType::REGULAR:
return _validator.evaluateStrength(std::string {password}, context.loginName, "").isValid();
case Database::UserType::DEMO:
return true; // no constraint
}
throw NotImplementedException {};
}
void
@@ -97,7 +106,7 @@ namespace Auth
if (!user)
throw Exception {"User not found!"};
if (!isPasswordSecureEnough(user->getLoginName(), newPassword))
if (!isPasswordSecureEnough(newPassword, PasswordValidationContext {user->getLoginName(), user->getType()} ))
throw PasswordTooWeakException {};
user.modify()->setPasswordHash(passwordHash);