Move internal authentication code to new function.

This is in preparation of adding LDAP based authentication.
Add function to check if user is an LDAP user.
Implement LDAPAuthenticate function.
Display use_ldap flag in user management.

Code for actually editing this boolean still needs writing.
Refactor to remove 'Arrow Anti-pattern'
Remove unused global variable not used in this function.
Merge pull request #130 from alexjfisher/master

Added initial LDAP support