Localization is a concerning issue in the applications of wireless sensor networks. Along with the accuracy of the location estimation of the sensor nodes, the security of the estimation is another priority. Wireless sensor networks often face various attacks where the attackers try to manipulate the estimated location or try to provide false beacons. In this paper, we have proposed a methodology that will address this problem of security aspects in localization of the sensor nodes. Moreover, we have considered the network environment with random node deployment and mobility as these two conditions are less addressed in previous research works. Further, our proposed algorithm provides low overhead due to the usage of less control messages in a limited transmission range. In addition, we have also proposed an algorithm to detect the malicious anchor nodes inside the network. The simulated results show that our proposed algorithm is efficient in terms of time consumption, localization accuracy, and localization ratio in the presence of malicious nodes.