By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,431 Members | 1,736 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,431 IT Pros & Developers. It's quick & easy.

verifying the password

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
prasi wrote:
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>

--
Peter

Nov 15 '05 #2

P: n/a
Peter Nilsson wrote:
prasi wrote:
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.


"All" is eighty percent correct.

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 15 '05 #3

P: n/a
In article <11*********************@g49g2000cwa.googlegroups. com>,
prasi <kp*********@gmail.com> wrote:
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.

Nov 15 '05 #4

P: n/a
prasi wrote:
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
Nov 15 '05 #5

P: n/a

prasi wrote:
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

Nov 15 '05 #6

P: n/a
Eric Sosman wrote:
Peter Nilsson wrote:
prasi wrote:
#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.


"All" is eighty percent correct.


You're being too kind. ;) It's actually 100% wrong.

Of course, <stdlib.h> _is_ a standard header.

Thanks.

--
Peter

Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.