7

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

1 Answers1

2

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.

Community
  • 1
  • 1
mti2935
  • 11,465
  • 3
  • 29
  • 33
  • 1
    but I can't the shadow file,if i am not root or at least my acoount is in the sudoers file.I want to check just for the root...not for every user. –  Dec 26 '14 at 10:45