intermediateManaging Users: UserDetailsService & UserDetailsManager

Can loadUserByUsername() be used with something other than a username, like an email or phone number?

Yes — the parameter name is just a String identifier; Spring Security doesn't care what business concept it represents. Many production systems pass an email address, employee ID, or phone number into this method; what matters is that your custom implementation correctly resolves that identifier to a unique user record.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why shouldn't you use encryption instead of hashing to store passwords?← Back to all Spring Security questions