Cannot remove "must change password" flag when creating user via CLI #11313

Closed
opened 2025-11-02 09:34:06 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @lonix1 on GitHub (Jul 24, 2023).

Description

Issue 1: --must-change-password switch ignored

I use the CLI to create a user:

$ gitea admin user create \
  --admin \
  --username foo \
  --password bar \
  --email foo@example.com \
  --must-change-password false

That works.

But the --must-change-password switch is ignored - because on first login, the user is forced to change the password.

Issue 2: must-change-password option doesn't work

As a workaround, I tried to unset that flag from the user account:

$ gitea admin user must-change-password foo --unset
$ gitea admin user must-change-password foo --unset true       # also tried this

But that responds with:

Updated 0 users setting MustChangePassword to true

And user still has to change password.

Issue 3: change-password option doesn't remove password change flag

So as another workaround, I try to actually change the password:

gitea admin user change-password --username foo --password bar

Response:

foo's password has been successfully updated!

But the user still has to change the password.

Gitea Version

1.20.1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

docker

Database

SQLite

Originally created by @lonix1 on GitHub (Jul 24, 2023). ## Description ### Issue 1: `--must-change-password` switch ignored I use the [CLI](https://docs.gitea.com/administration/command-line#admin) to create a user: ```sh $ gitea admin user create \ --admin \ --username foo \ --password bar \ --email foo@example.com \ --must-change-password false ``` That works. But the `--must-change-password` switch is ignored - because on first login, the user is forced to change the password. ### Issue 2: `must-change-password` option doesn't work As a workaround, I tried to unset that flag from the user account: ```sh $ gitea admin user must-change-password foo --unset $ gitea admin user must-change-password foo --unset true # also tried this ``` But that responds with: > Updated 0 users setting MustChangePassword to true And user still has to change password. ### Issue 3: `change-password` option doesn't remove password change flag So as another workaround, I try to actually change the password: ```sh gitea admin user change-password --username foo --password bar ``` Response: > foo's password has been successfully updated! But the user still has to change the password. ## Gitea Version 1.20.1 ## Can you reproduce the bug on the Gitea demo site? No ## Log Gist _No response_ ## Screenshots _No response_ ## Git Version _No response_ ## Operating System _No response_ ## How are you running Gitea? docker ## Database SQLite
GiteaMirror added the type/bug label 2025-11-02 09:34:06 -06:00
Author
Owner

@jolheiser commented on GitHub (Jul 24, 2023):

- --must-change-password false
+ --must-change-password=false

Since --must-change-password is a bool flag, false is interpreted as an argument in your example. --must-change-password=false explicitly sets the flag to false.

@jolheiser commented on GitHub (Jul 24, 2023): ```diff - --must-change-password false + --must-change-password=false ``` Since `--must-change-password` is a bool flag, `false` is interpreted as an argument in your example. `--must-change-password=false` explicitly sets the flag to false.
Author
Owner

@wxiaoguang commented on GitHub (Jul 24, 2023):

Can you try 1.21-main nightly?

1.21 has switched a more stable approach for CLI option parsing.

@wxiaoguang commented on GitHub (Jul 24, 2023): Can you try 1.21-main nightly? 1.21 has switched a more stable approach for CLI option parsing.
Author
Owner

@lonix1 commented on GitHub (Jul 24, 2023):

@jolheiser Thanks for the tip. I'm trying it again now. The other issues are still there though.
@wxiaoguang Thanks. I will do that. I guess that makes the other issues obsolete.

I guess we can close this, since the CLI is better in "vNext"?

(PS great work on 1.20.0 ! It's massive.)

@lonix1 commented on GitHub (Jul 24, 2023): @jolheiser Thanks for the tip. I'm trying it again now. The other issues are still there though. @wxiaoguang Thanks. I will do that. I guess that makes the other issues obsolete. I guess we can close this, since the CLI is better in "vNext"? (PS great work on 1.20.0 ! It's massive.)
Author
Owner

@jolheiser commented on GitHub (Jul 24, 2023):

fwiw we just refactored to v2 which still uses the same logic for bool flags, so the fix remains the same.

@jolheiser commented on GitHub (Jul 24, 2023): fwiw we just refactored to v2 which still uses the same logic for bool flags, so the fix remains the same.
Author
Owner

@wxiaoguang commented on GitHub (Jul 24, 2023):

fwiw we just refactored to v2 which still uses the same logic for bool flags, so the fix remains the same.

Nope, I am sure v2 (1.21) is much better (outdated)

package main

import (
	"fmt"
	"github.com/urfave/cli/v2"
)

func main() {
	app := cli.NewApp()
	app.Flags = []cli.Flag{
		&cli.BoolFlag{
			Name:  "must-change-password",
			Usage: "Set this option to false to prevent forcing the user to change their password after initial login, (Default: true)",
		},
	}

	app.Action = func(ctx *cli.Context) error {
		fmt.Printf("must-change-password: %v\n", ctx.Bool("must-change-password"))
		return nil
	}

	_ = app.Run([]string{"test", "--must-change-password"})
	_ = app.Run([]string{"test", "--must-change-password=false"})
	_ = app.Run([]string{"test", "--must-change-password=true"})
}

Output:

 must-change-password: true   (for --must-change-password)
 must-change-password: false  (for --must-change-password=false)
 must-change-password: true   (for --must-change-password=true)
@wxiaoguang commented on GitHub (Jul 24, 2023): > fwiw we just refactored to v2 which still uses the same logic for bool flags, so the fix remains the same. ~~Nope, I am sure v2 (1.21) is much better~~ (outdated) <details> ``` package main import ( "fmt" "github.com/urfave/cli/v2" ) func main() { app := cli.NewApp() app.Flags = []cli.Flag{ &cli.BoolFlag{ Name: "must-change-password", Usage: "Set this option to false to prevent forcing the user to change their password after initial login, (Default: true)", }, } app.Action = func(ctx *cli.Context) error { fmt.Printf("must-change-password: %v\n", ctx.Bool("must-change-password")) return nil } _ = app.Run([]string{"test", "--must-change-password"}) _ = app.Run([]string{"test", "--must-change-password=false"}) _ = app.Run([]string{"test", "--must-change-password=true"}) } ``` Output: ``` must-change-password: true (for --must-change-password) must-change-password: false (for --must-change-password=false) must-change-password: true (for --must-change-password=true) ``` </details>
Author
Owner

@jolheiser commented on GitHub (Jul 24, 2023):

Yes, that example shows my suggested fix working. 🙂

It's just a side effect of how bool flags work with urfave.

In any case, I just wanted to clarify in case someone comes across this issue in the future.

@jolheiser commented on GitHub (Jul 24, 2023): Yes, that example shows my suggested fix working. 🙂 It's just a side effect of how bool flags work with urfave. In any case, I just wanted to clarify in case someone comes across this issue in the future.
Author
Owner

@wxiaoguang commented on GitHub (Jul 24, 2023):

I see your point (I misunderstood somewhat before, sorry)

@wxiaoguang commented on GitHub (Jul 24, 2023): I see your point (I misunderstood somewhat before, sorry)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#11313