Made Encryption Method

Placed encryption code inside a method to reduce the code duplication
for encrypting passwords.