#!/usr/bin/perl
# Yes, we were storing passwords in plain text.
use Digest::MD5 qw/md5/;
use strict;

my $datadir = shift;

opendir DATA, $datadir;
while (my $user = readdir(DATA)) {
	next if $user =~ /^\./;
	print "Processing $user\n";
	open P, "$datadir/$user/password";
	my $password = <P>;
	close P;
	chomp $password;

	my $md5password = md5($user . $password);

	rename "$datadir/$user/password", "$datadir/$user/password.old";
	open P, ">$datadir/$user/password";
	print P $md5password;
	close P;
}
