#!/usr/local/bin/perl
dbmopen(%DB::CONFIG,"/usr/local/db/rocemabra.com/email/config",undef);
dbmopen(%DB,"/usr/local/db/rocemabra.com/email/db",undef);
$CUSTOM{CHECKSUMRANDOMIZER}=$DB::CONFIG{CHECKSUMRANDOMIZER};
while($key eq "" || defined $DB{"$key:DateEstab"}){
	$key=sprintf("%07d",int(rand(9999999))+1);
	$checksum=&checksum($key);
	$key="$key$checksum";
}
print "$key\n";
sub checksum{
########################################################################
# checksum routine used to establish/verify ID. Given arbitrary
# length numerical digit string, 2 digit checksum is produced. A
# per-database randomly generated integer is added to further secure.
########################################################################
	local(@digits);
	local($sum,$power,$digit);
	@digits=split('',shift);
	foreach $digit(@digits){
		$power++;
		$sum+=$digit*2**$power+$digit;
	}
	return (($sum+$CUSTOM{CHECKSUMRANDOMIZER})%100);
}
