{"record":{"id":"bf5a4dc0865f9097","repo":"docker/cli","slug":"conflicting-options-cannot-specify-both-passwor","errorCode":null,"errorMessage":"conflicting options: cannot specify both --password and --password-stdin","messagePattern":"conflicting options: cannot specify both --password and --password-stdin","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/registry/login.go","lineNumber":77,"sourceCode":"\t\tDisableFlagsInUseLine: true,\n\t}\n\n\tflags := cmd.Flags()\n\n\tflags.StringVarP(&opts.user, \"username\", \"u\", \"\", \"Username\")\n\tflags.StringVarP(&opts.password, \"password\", \"p\", \"\", `Password or Personal Access Token (PAT), or \"-\" to read from stdin`)\n\tflags.BoolVar(&opts.passwordStdin, \"password-stdin\", false, \"Take the Password or Personal Access Token (PAT) from stdin\")\n\n\treturn cmd\n}\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].","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/registry/login.go#L59-L95","documentation":"Thrown by verifyLoginFlags when both --password (with a value other than '-') and --password-stdin are set simultaneously. These are mutually exclusive ways to supply a credential and conflict with each other.","triggerScenarios":"Running 'docker login -u user --password secret --password-stdin' (login.go lines 75-78).","commonSituations":"Copy-pasting a command that included both flags; migrating from --password to --password-stdin without removing the old flag.","solutions":["Remove one of the two flags; keep only --password-stdin for security.","If you must pass the password inline, drop --password-stdin (note the CLI warns this is insecure)."],"exampleFix":"# before\ndocker login -u user --password secret --password-stdin\n# after\nprintf '%s' \"$PASS\" | docker login -u user --password-stdin","handlingStrategy":"validation","validationCode":"// Reject mutually exclusive password flags up front\nif passwordStdin && password != \"\" && password != \"-\" {\n    return fmt.Errorf(\"choose either --password or --password-stdin, not both\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on --password-stdin and never pass --password inline.","Lint CI scripts for the presence of both flags.","Treat --password as deprecated for security reasons."],"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"}