func (h *Handler) SetPassword(password string) error {
	logger := h.logger.Add("method", "SetPassword")

	logger.Debug("trying to set password")

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

	if err := h.validatePasswordNotSet(logger); err != nil {
		return err
	}

	salt := util.NewUUID()

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

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

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

	return commitTX(logger, tx)
}
func (h *Handler) SetPassword(password string) error {
	logger := h.logger.Add("method", "SetPassword")

	logger.Debug("trying to set password")

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

	if err := h.validatePasswordNotSet(logger); err != nil {
		return err
	}

	salt := util.NewUUID()

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

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

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

	return commitTX(logger, tx)
}
func ( h * Handler ) SetPassword ( password string ) error { logger := h . logger . Add ( " " , " " ) logger . Debug ( " " ) if password == " " { logger . Warn ( " " ) return ErrEmptyPassword } if err := h . validatePasswordNotSet ( logger ) ; err != nil { return err } salt := util . NewUUID ( ) hashed , err := hashedPassword ( logger , password , salt ) if err != nil { return err } tx , err := beginTX ( logger , h . db ) if err != nil { return err } defer tx . Rollback ( ) if err := insert ( logger , tx . Querier , saltSetting ( salt ) , passwordHashSetting ( hashed ) ) ; err != nil { return err } return commitTX ( logger , tx ) }
// SetPassword sets the password only on the first call.
// Returns error if password already exists.
SetPassword sets the password only on the first call . Returns error if password already exists .