check Linux password from /etc/shadow and C language

Hi.
I want to write a C Program that get a user name and password , then compare it with encrypted password in /etc/shadow.
I start with below program:

#define _XOPEN_SOURCE
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <crypt.h>

int main (void)
{
    char *passwd;
    passwd = crypt("123456", "$1$yfKCUYj6");

}

And then compile that:

gcc 1.c -o 1

The out put of compile is:

/tmp/cci2MSHh.o: In function `main':
1.c:(.text+0x21): undefined reference to `crypt'
collect2: ld returned 1 exit status

What is the problem? :frowning:

on my linux system, the man page for crypt specifically states

SYNOPSIS
       #define _XOPEN_SOURCE
       #include <unistd.h>

       char *crypt(const char *key, const char *salt);

       char *crypt_r(const char *key, const char *salt,
                     struct crypt_data *data);

       Link with -lcrypt.

if you change your compile to

gcc -lcrypt 1.c -o 1

then it should compile without errors.

Now how can I verify that with root password? and authentication?

how long is a piece of string?

which string?

less frivolously have you checked out the source code to login from any linux distribution, that will show you how it is done in linux, and should help you to understand how you wish to do it in the future
try here
http://anduin.linuxfromscratch.org/sources/LFS/lfs-packages/6.3/shadow-4.0.18.1.tar.bz2

I want to write a Socket Program, receive a message as a password (Plain text) and check that. Is that true or not.
How can checked out the source code to login from my Linux distribution?

I apologise, as english is obviously not your first language.
find a linux distribution that does cater for your language, download the shadow package for it, and within the shadow package will be the login utility code.
Once you see how login compares plain text with the encrypted text in the shadow file, it should be a trivial matter to add that process to any program