Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > verifying the password

Reply
Thread Tools

verifying the password

 
 
prasi
Guest
Posts: n/a
 
      10-25-2005
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

 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      10-25-2005
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

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      10-25-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      10-25-2005
In article <(E-Mail Removed). com>,
prasi <(E-Mail Removed)> 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.

 
Reply With Quote
 
Joe Estock
Guest
Posts: n/a
 
      10-25-2005
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
 
Reply With Quote
 
Singamsetty
Guest
Posts: n/a
 
      10-26-2005

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

 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      10-26-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change a users password without knowing the old password nor the answer to the password question AAaron123 ASP .Net 1 01-16-2009 02:56 PM
Changing a users password without knowing the old password nor the answer to the password question AAaron123 ASP .Net 2 01-16-2009 02:08 PM
Verifying someone is really certified. kb Microsoft Certification 3 07-30-2005 05:02 AM
verifying multicasting J R Cisco 3 09-02-2004 06:42 AM
Verifying Multicast Settings J R Cisco 2 08-20-2004 12:17 AM



Advertisments