#
#
# passwd.pl
#
# Get passwords to use for remote mode
# by Sam Kline, 5/00
#

sub change_passwd {

local ($user, $pass, $id, $name, $newpass, $saltindex, $salt);
open(OLDPASS, "< config/passwd");
open(NEWPASS, "> config/passwd.new");

while(<OLDPASS>) {
	($user, $pass, $id, $name) = split (/:/, $_, 4);
	print STDERR "Enter new password for \"$user\" or hit ENTER to leave as is\n";
	$newpass = "1";
	$newpass1 = "";
	while ($newpass ne $newpass1) {
	  print STDERR "Password:";
	  system("stty -echo");
	  $newpass = <>;
	  chop $newpass;
	  system("stty echo");
	  print STDERR "\n";
	  if ($newpass) {
	    print STDERR "Confirm Password:";
	    system("stty -echo");
	    $newpass1 = <>;
	    chop $newpass1;
	    system("stty echo");
	    print STDERR "\n";
	    print STDERR "Passwords do not match. Try again.\n"
	  	if ($newpass ne $newpass1)
	  }
	}
	if ($newpass) {
	  $salt = "";
	  while (length $salt < 2) {
	    $saltindex = rand(63);
	    if ($saltindex < 26) {
		$salt .= chr(ord('A') + $saltindex);
	    } elsif ($saltindex < 52) {
		$salt .= chr(ord('a') + $saltindex - 26);
	    } elsif ($saltindex < 62) {
		$salt .= chr(ord('0') + $saltindex - 52);
	    } else {
		$salt .= '/';
	    }
	  }
	  $pass = crypt($newpass, $salt);
	}
	print NEWPASS "$user:$pass:$id:$name";
}
close(OLDPASS);
close(NEWPASS);

system("mv config/passwd.new config/passwd");
}

1;
