Here's an even better how-to: Don't.
Preventing users from pasting into a password field is a terrible, terrible design. How is copying & pasting any different from using a password manager's auto-fill feature?
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.