verifying the password

P

prasi

I want to verify the password of a user by accepting the password and
comparing with the entry in the /etc/shadow file .But I a, getting an
error
The following code is giving one error
/home/training/prasanna/unix system programming/testpas.c:19: undefined
reference to `crypt'
collect2: ld returned 1 exit status

the code as foolows
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <crypt.h>
#include <stdlib.h>
#include <sys/types.h>
#include<pwd.h>


int main()
{
struct passwd *pw;

char *password="prasanna";
char *epass;
epass=(char*)malloc(20);
pw=getpwnam("prasanna");

epass=crypt(password,pw->pw_passwd);

if(strcmp(epass,pw->pw_passwd)==0)
printf("login success\n");
else
printf("login failure\n");

return 0;


}//end of main

please let me know why it ios giving the error

if the method i am following is not correct please tell me the other
alternative
thanks
prasi
 
P

Peter Nilsson

prasi said:
I want to verify the password of a user by accepting the password
and comparing with the entry in the /etc/shadow file .But I a,
getting an error
The following code is giving one error
/home/training/prasanna/unix system programming/testpas.c:19: undefined
reference to `crypt'
collect2: ld returned 1 exit status

the code as foolows
#include <stdio.h>
#include <string.h>

These are fine.
#include <unistd.h>
#include <crypt.h>
#include <stdlib.h>
#include <sys/types.h>
#include<pwd.h>

These are all headers which are not defined by the C language
standards.
And given that the crypt function is not standard to the C language
either, your query is off topic in comp.lang.c.

I suggest you try a unix related newsgroup.

[And learn to search for FAQ's and Welcome messages, as well lurking
before asking a question.]

<snip>
 
K

Kenny McCormack

I want to verify the password of a user by accepting the password and
comparing with the entry in the /etc/shadow file .But I a, getting an
error
The following code is giving one error
/home/training/prasanna/unix system programming/testpas.c:19: undefined
reference to `crypt'
collect2: ld returned 1 exit status

Not portable. Can't discuss it here. Blah, blah, blah.
 
J

Joe Estock

prasi said:
I want to verify the password of a user by accepting the password and
comparing with the entry in the /etc/shadow file .But I a, getting an
error
The following code is giving one error
/home/training/prasanna/unix system programming/testpas.c:19: undefined
reference to `crypt'
collect2: ld returned 1 exit status

the code as foolows
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <crypt.h>
#include <stdlib.h>
#include <sys/types.h>
#include<pwd.h>


int main()
{
struct passwd *pw;

char *password="prasanna";
char *epass;
epass=(char*)malloc(20);
pw=getpwnam("prasanna");

epass=crypt(password,pw->pw_passwd);

if(strcmp(epass,pw->pw_passwd)==0)
printf("login success\n");
else
printf("login failure\n");

return 0;


}//end of main

please let me know why it ios giving the error

if the method i am following is not correct please tell me the other
alternative
thanks
prasi
<OT>
You need to link with the crypt library. Try -lcrypt if you are using gcc
</OT>

-Joe
 
S

Singamsetty

prasi said:
I want to verify the password of a user by accepting the password and
comparing with the entry in the /etc/shadow file .But I a, getting an
error
The following code is giving one error
/home/training/prasanna/unix system programming/testpas.c:19: undefined
reference to `crypt'
collect2: ld returned 1 exit status

the code as foolows

.....[code snipped]
please let me know why it ios giving the error

if the method i am following is not correct please tell me the other
alternative
thanks
prasi

......you may find this link useful.
http://users.actcom.co.il/~choo/lupg/tutorials/user-info-api/user-info-api.html#users_authenticate

- Hemanth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,466
Latest member
DrusillaYa

Latest Threads

Top