aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/create-account/main.go30
1 files changed, 23 insertions, 7 deletions
diff --git a/cmd/create-account/main.go b/cmd/create-account/main.go
index 3003896c..307fa17e 100644
--- a/cmd/create-account/main.go
+++ b/cmd/create-account/main.go
@@ -48,24 +48,27 @@ Example:
# read password from stdin
%s --config dendrite.yaml -username alice -passwordstdin < my.pass
cat my.pass | %s --config dendrite.yaml -username alice -passwordstdin
+ # reset password for a user, can be used with a combination above to read the password
+ %s --config dendrite.yaml -reset-password -username alice -password foobarbaz
Arguments:
`
var (
- username = flag.String("username", "", "The username of the account to register (specify the localpart only, e.g. 'alice' for '@alice:domain.com')")
- password = flag.String("password", "", "The password to associate with the account (optional, account will be password-less if not specified)")
- pwdFile = flag.String("passwordfile", "", "The file to use for the password (e.g. for automated account creation)")
- pwdStdin = flag.Bool("passwordstdin", false, "Reads the password from stdin")
- askPass = flag.Bool("ask-pass", false, "Ask for the password to use")
- isAdmin = flag.Bool("admin", false, "Create an admin account")
+ username = flag.String("username", "", "The username of the account to register (specify the localpart only, e.g. 'alice' for '@alice:domain.com')")
+ password = flag.String("password", "", "The password to associate with the account (optional, account will be password-less if not specified)")
+ pwdFile = flag.String("passwordfile", "", "The file to use for the password (e.g. for automated account creation)")
+ pwdStdin = flag.Bool("passwordstdin", false, "Reads the password from stdin")
+ askPass = flag.Bool("ask-pass", false, "Ask for the password to use")
+ isAdmin = flag.Bool("admin", false, "Create an admin account")
+ resetPassword = flag.Bool("reset-password", false, "Resets the password for the given username")
)
func main() {
name := os.Args[0]
flag.Usage = func() {
- _, _ = fmt.Fprintf(os.Stderr, usage, name, name, name, name, name, name)
+ _, _ = fmt.Fprintf(os.Stderr, usage, name, name, name, name, name, name, name)
flag.PrintDefaults()
}
cfg := setup.ParseFlags(true)
@@ -93,6 +96,19 @@ func main() {
if *isAdmin {
accType = api.AccountTypeAdmin
}
+
+ if *resetPassword {
+ err = accountDB.SetPassword(context.Background(), *username, pass)
+ if err != nil {
+ logrus.Fatalf("Failed to update password for user %s: %s", *username, err.Error())
+ }
+ if _, err = accountDB.RemoveAllDevices(context.Background(), *username, ""); err != nil {
+ logrus.Fatalf("Failed to remove all devices: %s", err.Error())
+ }
+ logrus.Infof("Updated password for user %s and invalidated all logins\n", *username)
+ return
+ }
+
_, err = accountDB.CreateAccount(context.Background(), *username, pass, "", accType)
if err != nil {
logrus.Fatalln("Failed to create the account:", err.Error())