With the development of network, e-commerce has gradually become a new mode of human commercial activities. China's e-commerce is just beginning, and there are good prospects for development. However, with a growing number of users, the security issues become increasingly prominent. Now, to protect e-commerce sites and the users' information and property of these websites is a matter of great urgency. The paper analyzes security problems that exist in the e-commerce sites, and brings forward an improved BM-algorithm to solve these threats, which is named BMHSA algorithm. This algorithm can provide significant improvement in pattern matching performance.