Results 1 to 9 of 9

Thread: How to tell if user has changed password

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    417

    How to tell if user has changed password

    Hi,

    How can you tell if someone has changed their password or not?

    thanx,


  2. #2

    Re:How to tell if user has changed password

    Check the man page on 'shadow'. In unix, the third element is the last change date. It's expressed in the number of days from January 1, 1970.

  3. #3
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:How to tell if user has changed password

    yup, so a small proggy like this might do the trick:
    Code:
    #include <shadow.h>
    #include <stdio.h>
    #include <time.h>
    
    int main(int argc, char** argv)
    {
      struct spwd * pwd;
      int today, days, rest = 0;
      today = time(NULL);
      rest = today%86400;
      days = (today - rest)/86400;
      if(argc != 2)
        {
          printf("Usage: %s <user>\n", argv[0]);
          return -1;
        }
      if(!(pwd = getspnam(argv[1])))
        {
          printf("Sorry no such user found: %s\n", argv[1]);
          return -1;
        }
      printf("%d days since user %s last changed password.\n", (days - (*pwd).sp_lstchg), argv[1]);
      return 0;
    }
    Warning none of the above has been tested.

    ::edit::
    Changed some of the pointer arithmetic to conform with my compiler.. Still havn't tested any of it, but it compiles, so why wouldn't it work ?
    Just be root when running it, since a non root user can't access shadow.

  4. #4
    Senior Member
    Join Date
    Sep 2002
    Posts
    421

    Re:How to tell if user has changed password

    [quote author=redhead link=board=5;threadid=6824;start=0#63820 date=1050353343]
    Still havn't tested any of it, but it compiles, so why wouldn't it work ? [/quote]

    Hehe.

    "Hey, it compiles! Ship it!" - Microsoft QA

  5. #5

    Re:How to tell if user has changed password

    [quote author=demian link=board=5;threadid=6824;start=0#63850 date=1050402545]
    Hehe.

    "Hey, it compiles! Ship it!" - Microsoft QA
    [/quote]

    Or,

    Hmmm..It doesn't compile!! Oh well, ship it anyway! - Microsoft QA

  6. #6

    Re:How to tell if user has changed password

    [quote author=Stix link=board=5;threadid=6824;start=0#63868 date=1050428490]
    [quote author=demian link=board=5;threadid=6824;start=0#63850 date=1050402545]
    Hehe.

    "Hey, it compiles! Ship it!" - Microsoft QA
    [/quote]

    Or,

    Hmmm..It doesn't compile!! Oh well, ship it anyway! - Microsoft QA
    [/quote]

    we will just release a patch/service pack for it later :P

  7. #7
    Senior Member
    Join Date
    Apr 2002
    Posts
    417

    Re:How to tell if user has changed password

    I'm sorry I asked the wrong question.

    How can you tell when a specific user has changed their pasword. The code compiles and works but it only tell me how long it has been since the passwd file has changed.

    $> ll /etc/passwd

    tells me this aswell(the date it changed anyway).

    Can someone point me to where I can find out how password expiration is handled?

    thanx,

  8. #8

    Re:How to tell if user has changed password

    Hello,

    Maybe what you're looking for is as simple as
    Code:
    chage -l <username>
    as root.

    man chage for the rest of it's options.

    HTH,

    Stix


  9. #9

    Re:How to tell if user has changed password

    /etc/shadow holds that type of information too. Do a man on shadow. The file contains a warning to warn users that their password will expire. An epiration date etc. If you want some sore of logging, you can build a script that logs all change info., then kicks off the real passwd program. In other words, spoof the passwd executable.

Similar Threads

  1. User Password
    By MosMon in forum Linux - Hardware, Networking & Security
    Replies: 4
    Last Post: 06-10-2010, 05:30 AM
  2. User password expires automatically
    By Suhas! in forum Redhat / Fedora
    Replies: 2
    Last Post: 01-06-2009, 07:56 AM
  3. Access denied for user: '@192.168.0.71' (Using password: NO)
    By infinite_root in forum Linux - Hardware, Networking & Security
    Replies: 3
    Last Post: 11-20-2008, 02:10 AM
  4. How to add 100 User with default formated Password
    By daniel in forum Linux - General Topics
    Replies: 2
    Last Post: 07-13-2004, 09:45 AM
  5. Squirrel Mail-unknown user or password incorrect
    By rhonneil in forum Linux - Hardware, Networking & Security
    Replies: 0
    Last Post: 10-31-2003, 08:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •