in reply to Passwords on unix

Well advice from TheHobbit is hard to beat. But in the interest of answering the question, try this code:
#!/usr/bin/perl #Check password encryption $username = shift || die "Usage $0 username plaintext_password\n"; $plaintext = shift || die "Usage $0 username plaintext_password\n"; $encpass = (getpwnam($username))[1]; print "Testing encryption ... "; if (crypt($plaintext, $encpass) ne $encpass) { print "FAILED\nTrying MD5 encryption ... "; if ( eval "use Crypt::PasswdMD5" ) { print "FAILED\n\nCannot try MD5 since Crypt::PasswdMD5 is not inst +alled.\n"; } else { if (&unix_md5_crypt($plaintext, $encpass) ne $encpass) { print "FAILED\n\nUnable to automatically use passwords from your + system.\n"; } else { print "OK\n\nMD5 passwords were detected.\n"; } } } else { print "OK\n"; }

Replies are listed 'Best First'.
Re: Passwords on unix
by Abigail-II (Bishop) on Feb 04, 2003 at 20:39 UTC
    That approach is going to fail on any system that uses shadow password files. Many modern Unices use shadow password files.

    Abigail

      Abiigail-II said::

      That approach is going to fail on any system that uses shadow password files.

      I don't know why. getpwent() and friends do the right thing even in systems with shadow passwords, provided you are superuser.

      Perl's crypt() will call whatever crypt() is there in the system's library. Crypt::Passwd and Crypt::PasswdMD5 will cover the gap if you want to use a file from a different (incompatible) crypted password, but this is not the case at hand..

      Best regards

      -lem, but some call me fokat