diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4d9e9d1fb0..422882f651 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -104,10 +104,12 @@ static bool invalidPassword(const char* pPassword) { /* Execute regular expression */ int32_t res = regexec(®ex, pPassword, 0, NULL, 0); regfree(®ex); - if(0 != res) return false; + return 0 == res; +} +static bool invalidStrongPassword(const char* pPassword) { if (strcmp(pPassword, "taosdata") == 0) { - return false; + return true; } bool charTypes[4] = {0}; @@ -121,7 +123,7 @@ static bool invalidPassword(const char* pPassword) { } else if (taosIsSpecialChar(pPassword[i])) { charTypes[3] = true; } else { - return false; + return true; } } @@ -131,10 +133,10 @@ static bool invalidPassword(const char* pPassword) { } if (numOfTypes < 3) { - return false; + return true; } - return true; + return false; } static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, char* pPassword) { @@ -147,8 +149,16 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, (void)strdequote(pPassword); if (strtrim(pPassword) < TSDB_PASSWORD_MIN_LEN) { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_TOO_SHORT_OR_EMPTY); - } else if (invalidPassword(pPassword)) { - pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PASSWD); + } else { + if (tsEnableStrongPassword) { + if (invalidStrongPassword(pPassword)) { + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PASSWD); + } + } else { + if (invalidPassword(pPassword)) { + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PASSWD); + } + } } } return TSDB_CODE_SUCCESS == pCxt->errCode; diff --git a/tests/army/cluster/strongPassword.py b/tests/army/cluster/strongPassword.py index dc6dbd7c7e..311c77e158 100644 --- a/tests/army/cluster/strongPassword.py +++ b/tests/army/cluster/strongPassword.py @@ -27,11 +27,11 @@ class TDTestCase(TBase): def run(self): # strong - tdSql.error("create user test pass '12345678' sysinfo 0;", expectErrInfo="Invalid password format") + tdSql.error("create user test pass '12345678' sysinfo 0;", expectErrInfo="Invalid password") tdSql.execute("create user test pass '12345678@Abc' sysinfo 0;") - tdSql.error("alter user test pass '23456789'", expectErrInfo="Invalid password format") + tdSql.error("alter user test pass '23456789'", expectErrInfo="Invalid password") tdSql.execute("alter user test pass '23456789@Abc';")