Is there any C API for validating user name ?
I am taking input of user_name which might not be present at that point in time. Since the user name needs to follow POSIX rules, is there any C API which can do the validation?
Is there any C API for validating user name ?
I am taking input of user_name which might not be present at that point in time. Since the user name needs to follow POSIX rules, is there any C API which can do the validation?
I presume you are trying to figure out whether a user name exists on the system you are running on. For that, you are looking for getwpent()
/getpwnam()
-- check the manual page for details.
Although these return more information than you want, getpwnam()
will also (easily) tell you if there is or isn't a password file entry corresponding to a given user name.
(If you are simply looking to make sure a user name contains only valid characters, just make sure it only contains [A-Za-z0-9_]+
)