Get short username from

Does anyone know how to get the short username for example. "johnsmith" given their full name, eg. "John Smith"?

Note. I am interested in any user, not the current user, so the NSUserName functions are irrelevant.

Why? I authenticate username and password using authorization services. This allows people to enter either their short name or full name, which is nice, but I then need to know who they are actually logged in to (such as short username and / or user ID).

Disgusting hacks like [NSHomeDirectoryForUser (username) lastPathComponent] don't work consistently.

+2


source to share


1 answer


You need to use Collaboration Framework :). Link this structure to your project and then you just need to do the following:

CBIdentity* identity = [CBIdentity identityWithName:@"John Smith" authority:[CBIdentityAuthority localIdentityAuthority]];
NSLog(@"Posix name: %@", [identity posixName]);

      



And voila!

EDIT: If you only need to find users who are network bound, you need to use +managedIdentityAuthority

instead +localIdentityAuthority

. And if you need to find both local users and network users, use +defaultIdentityAuthority

.

+6


source







All Articles