Software Freedom Law Center

root/trunk/scripts/ldap/generate-ldap-password.plx

Revision 32, 1.4 kB (checked in by bkuhn, 1 year ago)

# Minor formatting changes

Line 
1 #!/usr/bin/perl
2 #  Copyright 2006, Software Freedom Law Center, Inc.
3 #
4 # This software gives you freedom; it is licensed to you under version 3
5 # of the GNU General Public License.
6 #
7 # This software is distributed WITHOUT ANY WARRANTY, without even the
8 # implied warranties of MERCHANTABILITY and FITNESS FOR A PARTICULAR
9 # PURPOSE.  See the GNU General Public License for further details.
10 #
11 # You should have received a copy of the GNU General Public License,
12 # version 3.  If not, see <http://www.gnu.org/licenses/>
13 #
14 # License: GPLv3-only
15
16 use strict;
17 use warnings;
18
19 use Term::ReadKey;
20 use Digest::SHA1;
21 use MIME::Base64;
22 use File::Temp qw(:mktemp);
23
24 sub GenerateLDAPPassword ($) {
25   my($clearTextPW) = @_;
26
27   my $ctx = Digest::SHA1->new;
28   $ctx->add($clearTextPW);
29
30   open(RANDOM, "/dev/urandom") || die "You have no /dev/urandom!";
31   my $ii;
32   while (read(RANDOM, $ii, 64) != 64) {  }
33   my $salt = unpack("a*", $ii);
34
35   $ctx->add($salt);
36   my $hashedPasswd = '{SSHA}' . encode_base64($ctx->digest . $salt ,'');
37   return $hashedPasswd;
38
39 }
40 print "New password: ";
41 ReadMode 'noecho';
42 my $password = ReadLine(0);
43 chomp $password;
44 print "\n";
45 ReadMode 'normal';
46 print "Re-enter new password: ";
47 ReadMode 'noecho';
48 my $second = ReadLine(0);
49 chomp $second;
50 ReadMode 'normal';
51 print "\n";
52 if ($password ne $second) {
53   print "\nPasswords do not match.  Aborting.\n";
54   exit 1;
55 }
56 print GenerateLDAPPassword($password), "\n";
Note: See TracBrowser for help on using the browser.

SFLC Main Page

[frdm] Support SFLC