Phase randomization improves the security of quantum key distribution