verifying the password

Discussion in 'C Programming' started by prasi, Oct 25, 2005.

  1. prasi

    prasi Guest

    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
     
    prasi, Oct 25, 2005
    #1
    1. Advertising

  2. 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
     
    Peter Nilsson, Oct 25, 2005
    #2
    1. Advertising

  3. prasi

    Eric Sosman Guest

    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
    lid
     
    Eric Sosman, Oct 25, 2005
    #3
  4. In article <>,
    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


    Not portable. Can't discuss it here. Blah, blah, blah.
     
    Kenny McCormack, Oct 25, 2005
    #4
  5. prasi

    Joe Estock Guest

    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
     
    Joe Estock, Oct 25, 2005
    #5
  6. prasi

    Singamsetty Guest

    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
     
    Singamsetty, Oct 26, 2005
    #6
  7. 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
     
    Peter Nilsson, Oct 26, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. julian

    Verifying a URL

    julian, Jul 17, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    396
    Mario Vargas
    Jul 17, 2003
  2. John

    Verifying users

    John, Oct 3, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    433
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Oct 4, 2004
  3. Tim

    Verifying web.config

    Tim, Apr 4, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    413
  4. AAaron123
    Replies:
    2
    Views:
    2,194
    AAaron123
    Jan 16, 2009
  5. AAaron123
    Replies:
    1
    Views:
    1,350
    Oriane
    Jan 16, 2009
Loading...

Share This Page