ui/auth.go
func (h *Handler) UpdatePassword(current, new string) error {
	logger := h.logger.Add("method", "UpdatePassword")

	if err := h.checkPassword(logger, current); err != nil {
		return err
	}

	logger.Debug("updating password")

	if new == "" {
		logger.Warn("received empty password for update")
		return ErrEmptyPassword
	}

	salt := util.NewUUID()

	hashed, err := hashedPassword(logger, new, salt)
	if err != nil {
		return err
	}

	tx, err := beginTX(logger, h.db)
	if err != nil {
		return err
	}
	defer tx.Rollback()

	if err := h.updatePrivateKeys(logger, tx, current, new); err != nil {
		return err
	}

	if err := update(logger, tx.Querier,
		saltSetting(salt), passwordHashSetting(hashed)); err != nil {
		return err
	}

	err = commitTX(logger, tx)
	if err != nil {
		return err
	}

	h.token.Make()

	return nil
}
func (h *Handler) UpdatePassword(current, new string) error {
	logger := h.logger.Add("method", "UpdatePassword")

	if err := h.checkPassword(logger, current); err != nil {
		return err
	}

	logger.Debug("updating password")

	if new == "" {
		logger.Warn("received empty password for update")
		return ErrEmptyPassword
	}

	salt := util.NewUUID()

	hashed, err := hashedPassword(logger, new, salt)
	if err != nil {
		return err
	}

	tx, err := beginTX(logger, h.db)
	if err != nil {
		return err
	}
	defer tx.Rollback()

	if err := h.updatePrivateKeys(logger, tx, current, new); err != nil {
		return err
	}

	if err := update(logger, tx.Querier,
		saltSetting(salt), passwordHashSetting(hashed)); err != nil {
		return err
	}

	err = commitTX(logger, tx)
	if err != nil {
		return err
	}

	h.token.Make()

	return nil
}
// UpdatePassword updates the password.