mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Re-add possibilty to create passwordless account
This commit is contained in:
parent
1f21b7c8d9
commit
444660c7bc
|
|
@ -58,6 +58,7 @@ var (
|
|||
password = flag.String("password", "", "The password to associate with the account")
|
||||
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")
|
||||
pwdLess = flag.Bool("passwordless", false, "Create a passwordless account, e.g. if only an accesstoken is required")
|
||||
isAdmin = flag.Bool("admin", false, "Create an admin account")
|
||||
resetPassword = flag.Bool("reset-password", false, "Resets the password for the given username")
|
||||
validUsernameRegex = regexp.MustCompile(`^[0-9a-z_\-=./]+$`)
|
||||
|
|
@ -76,19 +77,27 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *pwdLess && *resetPassword {
|
||||
logrus.Fatalf("Can not reset to an empty password, unable to login afterwards.")
|
||||
}
|
||||
|
||||
if !validUsernameRegex.MatchString(*username) {
|
||||
logrus.Warn("Username can only contain characters a-z, 0-9, or '_-./='")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(fmt.Sprintf("@%s:%s", *username, cfg.Global.ServerName)) > 255 {
|
||||
logrus.Fatalln("Username can not be longer than 255 characters.")
|
||||
logrus.Fatalf("Username can not be longer than 255 characters: %s", fmt.Sprintf("@%s:%s", *username, cfg.Global.ServerName))
|
||||
}
|
||||
|
||||
pass, err := getPassword(*password, *pwdFile, *pwdStdin, os.Stdin)
|
||||
var pass string
|
||||
var err error
|
||||
if !*pwdLess {
|
||||
pass, err = getPassword(*password, *pwdFile, *pwdStdin, os.Stdin)
|
||||
if err != nil {
|
||||
logrus.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
b := base.NewBaseDendrite(cfg, "create-account")
|
||||
accountDB := b.CreateAccountsDB()
|
||||
|
|
@ -147,7 +156,6 @@ func getPassword(password, pwdFile string, pwdStdin bool, r io.Reader) (string,
|
|||
return strings.TrimSpace(string(data)), nil
|
||||
}
|
||||
|
||||
if password == "" && pwdFile == "" && !pwdStdin {
|
||||
// If no parameter was set, ask the user to provide the password
|
||||
fmt.Print("Enter Password: ")
|
||||
bytePassword, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||
|
|
@ -165,6 +173,5 @@ func getPassword(password, pwdFile string, pwdStdin bool, r io.Reader) (string,
|
|||
return "", fmt.Errorf("Entered passwords don't match")
|
||||
}
|
||||
return strings.TrimSpace(string(bytePassword)), nil
|
||||
}
|
||||
return password, nil
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ func Test_getPassword(t *testing.T) {
|
|||
},
|
||||
want: pass,
|
||||
},
|
||||
{
|
||||
name: "pwdFile does not exist",
|
||||
args: args{pwdFile: "iDontExist"},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "read pass from stdin defined",
|
||||
args: args{
|
||||
|
|
|
|||
Loading…
Reference in a new issue