chiark / gitweb /
Default "overlapping" to relevant ones when you view a record or pick a network.
[bcp5-registry.git] / passwords.pl
1 # Password handling.
2 #
3 # Copyright (C) 1999 Ian Jackson <ijackson@chiark.greenend.org.uk>
4 #
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.
9 #
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.
14 #
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.
18
19 use MD5;
20
21 sub check_password () {
22     my ($pw);
23     $password= $in{'pw'};
24     length $password or finish_error('nopassword');
25     defined $ent or die;
26
27     open P,"pwkeys" or die $!;
28     for (;;) {
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
33     }
34     close P;
35 }
36
37 sub calc_password ($$) {
38     my ($keyhex,$id) = @_;
39     # keys are hex-encoded octet strings; ids are just ASCII strings
40     my ($key);
41
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);
46 }
47
48 sub make_password ($) {
49     my ($keyhex,$pw);
50
51     open P,"pwkeys" or die $!;
52     $keyhex= <P>; $keyhex =~ s/\n$// or die $!;
53     $pw= calc_password($keyhex,$id);
54     close P;
55     return $pw;
56 }
57
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 $?;
64 }
65
66 1;