Test password against /etc/passwd

This is a discussion on Test password against /etc/passwd within the Linux Programming forums, part of the Platform Specific Boards category; Refer to FAQ some part of it didn't compile Code: //Test a plain text password against an /etc/passwd entry #include ...

  1. #1
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187

    Test password against /etc/passwd

    Refer to FAQ some part of it didn't compile
    Code:
    //Test a plain text password against an /etc/passwd entry
    #include <sys/types.h>
    #include <pwd.h>
    #include <unistd.h>
    
    int main()
    {
      struct passwd *p;
      p=getpwnam(getlogin());
      if (p)
        if (strcmp((char*)crypt("password",p->pw_passwd),p->pw_passwd)==0)
          puts("match");
        else
          puts("not match");
      return 0;
    }
    $ gcc source.c
    /tmp/ccmmZota.o: In function `main':
    /tmp/ccmmZota.o(.text+0x42): undefined reference to `crypt'
    collect2: ld returned 1 exit status

    comment: I modified some part i.e. I cast crypt() to (char *), else more error would be generated.
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  2. #2
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    Deeply thanks, vVv
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  3. #3
    Woodoo
    Guest
    Yes, it compiles on my machine. But the result is never ``match'', even if I put correct password. Could any one help me out? The code seems OK.

  4. #4
    cgoat
    Guest
    I think you may need to read the encrypted password from /etc/shadow, using getspent(). Although you have to be super-user to access the shadow file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Integer Emulation
    By Elysia in forum C++ Programming
    Replies: 31
    Last Post: 03-18-2008, 02:03 PM
  2. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  3. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 01:55 PM
  4. MSVC Template Constructor/Assignment Errors
    By LuckY in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 03:57 PM
  5. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 09:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21