The open and anonymous nature of a P2P network makes it an ideal medium for attackers to spread malicious content. In this paper, we propose a reputation-based trust management system for P2P networks that aims to build confidence among the good members of the community and identify the malicious ones. The proposed system is simple and efficient in design and can be integrated into most first generation P2P systems easily. A diverse set of simulation experiments conducted to test the performance of the system show that it can be highly effective in preventing the spread of malicious content. The proposed system has other potential benefits as well, such as supporting the detection of free riders in a file sharing application.