I've inherited a custom made authentication system that needs some refactoring. I'm not quite sure what the best way to split it up the password section and could use some help.
The password class(es) need the following functionality:
- Check to see if a password conforms to restrictions. It needs to be able to provide feedback on why it is incorrect.
- Generate three kinds of hashes. We have several file-systems with incompatible hashes, so unfortunately I have to maintain three hashes.
- Give a different hash for a certain user type. If a user is web-only we do not keep a password for them as they cannot use the system. Their passwords are always
- Be able to verify a password for a given user. Fortunately I only have to authenticate against one of the three hashes I have to maintain.
- Be able to generate a random password, unencrypted.
- Submit new password to the database.
I'm thinking about using four classes,
isCurrentPassword(int userid, string password): bool
getViolations(string password): array
generate(int length):stringCreates a password.
hash_*(string password): stringwhere
*is the hash type. I'll have four hashing functions.
change(int userid, string password):void; throws database exceptions
What would you recommend and why?