[oclug] perl - getting equiv of linux shadow/md5 passwords

Dave O'Neill dmo at acm.org
Wed Apr 16 13:02:13 EDT 2003


On Wed, Apr 16, 2003 at 12:31:38PM -0400, Jon Earle wrote:
> 
> Hey folks,
> 
> If there a way in perl to get the equivalent of the shadow password entry
> for a user?  My func:

 [ snip ]

Yep, crypt() will do it for you for free.  Your salt has to start with the
characters '$1$', followed by up to eight more characters (alphanumeric and
.) and an optional trailing $.  

Here's an example ripped out of a larger chunk of working code:

	my @chars = ('a'..'z','A'..'Z',0..9,'.');
	my $salt = '';
	for(1..8) {
  	      $salt .= $chars[int(rand(scalar(@chars)))];
	}
	my $crypted_pass = crypt($plaintext,'$1$' . $salt ) 
        	or die($!);

Dave
-- 
    ``A popular response is: "If you have nothing to hide, you have nothing
 ('>  to fear." [...] The truth is that we all do have something to hide, 
 //\  not because it's criminal or even shameful, but simply because it's 
 V_/_ private.'' - George Radwanski, Privacy Commissioner of Canada.



More information about the OCLUG mailing list