# This perl subroutine will encrypt passwords
# The use of the subroutine is:
#	require "/mcs/adm/lib/perl/encrypt_passwd";
#	$crypted = &encrypted_passwd( $plaintext, $salt );
#	
#  --Mark Henderson

sub encrypt_passwd {
  local($user,$pass)=@_;
  local($nsalt,$week,$now,$pert1,$pert2);
  local(@salt_set)=('a'..'z','A'..'Z','0'..'9','.','/');
  $now=time;
  ($pert1,$pert2) = unpack("C2",$user);
  $week = $now / (60*60*24*7) + $pert1 + $pert2;
  $nsalt = $salt_set[$week % 64] . $salt_set[$now %64];
  return crypt($pass,$nsalt);
}
1;
