1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-21 19:03:26 +01:00

Do not allow empty passwords when creating users

This commit is contained in:
binwiederhier 2023-11-19 05:47:41 -05:00
parent 497f45e5cd
commit 1c3ed3ea40
2 changed files with 7 additions and 2 deletions

View file

@ -198,7 +198,6 @@ func execUserAdd(c *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
password = p password = p
} }
if err := manager.AddUser(username, password, role); err != nil { if err := manager.AddUser(username, password, role); err != nil {
@ -343,6 +342,8 @@ func readPasswordAndConfirm(c *cli.Context) (string, error) {
password, err := util.ReadPassword(c.App.Reader) password, err := util.ReadPassword(c.App.Reader)
if err != nil { if err != nil {
return "", err return "", err
} else if len(password) == 0 {
return "", errors.New("password cannot be empty")
} }
fmt.Fprintf(c.App.ErrWriter, "\r%s\rconfirm: ", strings.Repeat(" ", 25)) fmt.Fprintf(c.App.ErrWriter, "\r%s\rconfirm: ", strings.Repeat(" ", 25))
confirm, err := util.ReadPassword(c.App.Reader) confirm, err := util.ReadPassword(c.App.Reader)

View file

@ -253,6 +253,8 @@ func ReadPassword(in io.Reader) ([]byte, error) {
password, err := term.ReadPassword(int(f.Fd())) // This is always going to be 0 password, err := term.ReadPassword(int(f.Fd())) // This is always going to be 0
if err != nil { if err != nil {
return nil, err return nil, err
} else if len(password) == 0 {
return nil, errors.New("password cannot be empty")
} }
return password, nil return password, nil
} }
@ -272,7 +274,9 @@ func ReadPassword(in io.Reader) ([]byte, error) {
} }
password = append(password, buf[0]) password = append(password, buf[0])
} }
if len(password) == 0 {
return nil, errors.New("password cannot be empty")
}
return password, nil return password, nil
} }