{"record":{"id":"5ac5a16c54ddf1b2","repo":"bytebase/bytebase","slug":"password-must-contains-at-least-1-number","errorCode":null,"errorMessage":"password must contains at least 1 number","messagePattern":"password must contains at least 1 number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/common/password.go","lineNumber":18,"sourceCode":"//nolint:revive\npackage common\n\nimport (\n\t\"regexp\"\n\n\t\"github.com/pkg/errors\"\n\n\tstorepb \"github.com/bytebase/bytebase/backend/generated-go/store\"\n)\n\n// ValidatePassword validates a password against the workspace password restrictions.\nfunc ValidatePassword(password string, restriction *storepb.WorkspaceProfileSetting_PasswordRestriction) error {\n\tif len(password) < int(restriction.GetMinLength()) {\n\t\treturn errors.Errorf(\"password length should no less than %v characters\", restriction.GetMinLength())\n\t}\n\tif restriction.GetRequireNumber() && !regexp.MustCompile(\"[0-9]+\").MatchString(password) {\n\t\treturn errors.Errorf(\"password must contains at least 1 number\")\n\t}\n\tif restriction.GetRequireLetter() && !regexp.MustCompile(\"[a-zA-Z]+\").MatchString(password) {\n\t\treturn errors.Errorf(\"password must contains at least 1 lower case letter\")\n\t}\n\tif restriction.GetRequireUppercaseLetter() && !regexp.MustCompile(\"[A-Z]+\").MatchString(password) {\n\t\treturn errors.Errorf(\"password must contains at least 1 upper case letter\")\n\t}\n\tif restriction.GetRequireSpecialCharacter() && !regexp.MustCompile(`[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]+`).MatchString(password) {\n\t\treturn errors.Errorf(\"password must contains at least 1 special character\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/common/password.go#L1-L31","documentation":"ValidatePassword checks restriction.RequireNumber: when enabled, the password must match the regex [0-9]+. This error means RequireNumber is on in workspace password restrictions but the submitted password contains no digit at all.","triggerScenarios":"Password reset or creation (via ResetUserPassword / validatePasswordWithRestriction) submits a password with zero digits while WorkspaceProfileSetting_PasswordRestriction.RequireNumber is true.","commonSituations":"Admin enables \"must contain number\" and users' dictionary-style passwords fail; automated scripts generating passwords without digits; users enabling password managers that generate letters-only passwords is rare but policy config is often forgotten.","solutions":["Include at least one digit (0-9) in the password.","Read the workspace password restriction settings first and generate/validate passwords that satisfy RequireNumber before calling the API.","If the digit requirement is unwanted, have an admin disable RequireNumber in workspace settings."],"exampleFix":"// before\npassword := \"abcdefghij\" // no digit\n// after\npassword := \"abcdefghj1\" // contains a digit","handlingStrategy":"validation","validationCode":"func hasDigit(s string) bool {\n  return regexp.MustCompile(\"[0-9]+\").MatchString(s)\n}","typeGuard":null,"tryCatchPattern":"if err := common.ValidatePassword(pwd, restriction); err != nil {\n  return status.Errorf(codes.InvalidArgument, \"password rejected: %s\", err.Error())\n}","preventionTips":["Validate passwords against all workspace restriction flags client-side before submit","Configure generators to always include a digit","Show the digit requirement in the UI as a live checklist"],"tags":["password","validation","policy"],"backgroundTag":"schema-validation-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}