Moved password hashing to separate function

Moved the password hashing into a separate function.

Just in case the hashing method needs to be changed in future to something more secure, you will only have to change it in one place.

Make sure you pull #5 first.