user4272649
user4272649

Reputation:

Check the root password

What is the best way to check if a root linux password is correct,from a c program.One solution is tu run a command like : echo \"myPass\n"\ | sudo -S mySudoPassword and somehow check stderr to see if contains data.I am looking forward to get an elegant solution

Upvotes: 7

Views: 28611

Answers (1)

mti2935
mti2935

Reputation: 12027

You can validate that a given password is correct for a given username using the shadow file.

See Given a linux username and a password how can I test if it is a valid account? for the mechanics of how this is done. It should be possible to perform the same operations in a C program.

Upvotes: 2

Related Questions