On Wed, Jul 24, 2002 at 12:08:22PM +1000, Peter Rundle wrote:
> Yes in Linux. Ok example, lets say there is a user on the system called
> "kevin" (in your honour ;-) and he has a password that is encrypted in
> the shadow file. Now this script is being run by someone who claims to
> be kevin, but I want to be sure, so I prompt them to keyin their password
> which I jam into a variable in the script, is there a system command
> that will allow me to check the password is valid? I.E the user kevin
> could logon to Linux with it.
> 
> It would be nice if it was a system call because then if the system is
> Pam'd onto Ldap or whatever then my shell doesn't have to worry about
> that. I.E I'd rather not encrypt the string and match it to the
> /etc/shadow entry in case the system doesn't use shadow password's
> etc.

Perl:

  print "Username? ";
  $username = <STDIN>;
  print "Password? ";
  $userpass = <STDIN>;
  $passwd = (getpwnam($username))[1];
  print (crypt($userpass, $passwd) eq $passwd) ? "okay\n" : "bad\n";

This works with conventional crypt passwords and with shadows if you're
root. I think it should work with other pamified things as well because 
it's just calling the system library getpwnam().

Cheers,
Gavin

-- 
Fashion is a variable, but style is a constant - Programming Perl
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to