Add rubocop and fix problems it detected

Includes some refactoring of the password method to reduce its length.