{"record":{"id":"445447c4a09d1464","repo":"docker/cli","slug":"password-is-empty","errorCode":null,"errorMessage":"password is empty","messagePattern":"password is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/registry/login.go","lineNumber":87,"sourceCode":"}\n\n// verifyLoginFlags validates flags set on the command.\n//\n// TODO(thaJeztah); combine with verifyLoginOptions, but this requires rewrites of many tests.\nfunc verifyLoginFlags(flags *pflag.FlagSet, opts loginOptions) error {\n\tif flags.Changed(\"password-stdin\") || opts.password == \"-\" {\n\t\tif flags.Changed(\"password\") && opts.password != \"-\" {\n\t\t\treturn errors.New(\"conflicting options: cannot specify both --password and --password-stdin\")\n\t\t}\n\t\tif !flags.Changed(\"username\") {\n\t\t\treturn errors.New(\"the --password-stdin option requires --username to be set\")\n\t\t}\n\t}\n\tif flags.Changed(\"username\") && opts.user == \"\" {\n\t\treturn errors.New(\"username is empty\")\n\t}\n\tif flags.Changed(\"password\") && opts.password == \"\" {\n\t\treturn errors.New(\"password is empty\")\n\t}\n\treturn nil\n}\n\n// readSecretFromStdin reads the secret from r and returns it as a string.\n// It trims terminal line-endings (LF, CRLF, or CR), which may be added when\n// inputting interactively or piping input. The value is otherwise treated as\n// opaque, preserving any other whitespace, including newlines, per [NIST SP 800-63B §5.1.1.2].\n// Note that trimming whitespace may still happen elsewhere (see [NIST SP 800-63B (revision 4) §3.1.1.2]);\n//\n// > Verifiers **MAY** make limited allowances for mistyping (e.g., removing\n// > leading and trailing whitespace characters before verification, allowing\n// > the verification of passwords with differing cases for the leading character)\n//\n// [NIST SP 800-63B §5.1.1.2]: https://pages.nist.gov/800-63-3/sp800-63b.html#memsecretver\n// [NIST SP 800-63B (revision 4) §3.1.1.2]: https://pages.nist.gov/800-63-4/sp800-63b.html#passwordver\nfunc readSecretFromStdin(r io.Reader) (string, error) {\n\tb, err := io.ReadAll(r)","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/registry/login.go#L69-L105","documentation":"Thrown by verifyLoginFlags when the --password flag was explicitly changed but resolves to an empty string, e.g. 'docker login -u user --password \"\"'. The flag-level guard (lines 86-87) treats an explicitly-empty password as invalid.","triggerScenarios":"Running 'docker login -u user --password \"\"' or '--password=' with an empty value at the flag-parsing stage.","commonSituations":"Passing an unset shell variable as the password: 'docker login -u user -p $EMPTY'; misconfigured CI secret that resolves to empty.","solutions":["Provide a non-empty password or, preferably, use --password-stdin.","Verify the secret/env var is populated before running the command."],"exampleFix":"# before\ndocker login -u user --password \"\"\n# after\nPASS=${PASS:?empty}; printf '%s' \"$PASS\" | docker login -u user --password-stdin","handlingStrategy":"validation","validationCode":"// Reject an explicitly empty --password\nif flags.Changed(\"password\") && strings.TrimSpace(opts.password) == \"\" {\n    return fmt.Errorf(\"--password must not be empty\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer --password-stdin over inline --password.","Verify CI secrets are populated before the command.","Quote password variables and check for emptiness."],"tags":["registry","login","auth","docker","go","cli","flags"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}