3 # Copyright (C) 1999 Ian Jackson <ijackson@chiark.greenend.org.uk>
5 # This is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2,
8 # or (at your option) any later version.
10 # This is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public
16 # License along with this file; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 sub check_password () {
24 length $password or finish_error('nopassword');
27 open P,"pwkeys" or die $!;
29 $_= <P>; die $! unless length; chomp;
30 finish_error('badpassword') if m/^end$/;
31 $pw= calc_password($_,$id);
32 last if lc $pw eq lc $password
37 sub calc_password ($$) {
38 my ($keyhex,$id) = @_;
39 # keys are hex-encoded octet strings; ids are just ASCII strings
42 $keyhex =~ m/^[0-9a-f]+$/ or die "$keyhex ?";
43 $key= pack('H*',$keyhex);
44 $digest= MD5->hash("BCP5Registry password 1 $id ".$key);
45 return unpack('H20',$digest);
48 sub make_password ($) {
51 open P,"pwkeys" or die $!;
52 $keyhex= <P>; $keyhex =~ s/\n$// or die $!;
53 $pw= calc_password($keyhex,$id);
58 sub send_password ($) {
59 $password= make_password($id);
60 process_file('notice.txt');
61 open SM, "| /usr/sbin/sendmail -odb -oi -oee -f $nullemail -t" or die $!;
62 print SM $out or die $!;
63 close SM; $? and die $?;