How to enter new password on iphone?

I had to get a new password for my iphone 4g as my account was hacked

Settings/General/Passcode Lock. Enter your passcode and there will be a button at the top to Change the passcode. This will change the passcode on your phone itself.

As for any account on the internet that's been hacked, you would have to change the password there using whatever method the website requires. Then you would change the passcode on the app in the iPhone that accesses that site.