#!/usr/pkg/bin/perl -w
#
# Enc(rypt)ProxyPasswd Prototype 27
# Simple MD5 password encrypter
#
# Copyright Dirk Diggler & Som One 1981-2003. All rides reserved.
# Coded by Pierrot Lunaire
# Redistribution and use, with or without modification,
# is permitted in the sense of GDWYWL
# (GeneralDoWhateverYouWantLicense).
# -z3r0-

use strict;

BEGIN {
  eval "use Term::ReadKey";
  if ($@) {
  print "EncProxyPasswd: Cannot find Term::ReadKey perl module.\n\n".
        "You need to have this module installed in order to run EncProxyPasswd.\n".
        "See README for more info on how to install the module.\n\n";
  die "\n";
  }
  eval "use MIME::Base64";
  if ($@) {
  print "EncProxyPasswd: Cannot find MIME::Base64 perl module.\n\n".
        "You need to have this module installed in order to run EncProxyPasswd.\n".
        "See README for more info on how to install the module.\n\n";
  die "\n";
  }
}

my $temp1;
my $temp2;
my $temp3;

print "\n";
print "Please enter your PROXY username: ";
$temp3 = ReadLine 0;

# Turn off terminal output
ReadMode 'noecho';

do {
    if ($temp1) {print "\nERROR: The strings didn\'t match. Please retry...\n\n"}

    print "Please enter your PROXY password: ";
    $temp1 = ReadLine 0;
    chomp($temp1);

    print "\nPlease re-enter your PROXY password: ";
    $temp2 = ReadLine 0;
    chomp($temp2);

    print "\n";
} until $temp1 eq $temp2;

# Turn back on terminal output
ReadMode 'normal';

chomp($temp1);
chomp($temp3);

my $hash = encode_base64("$temp3:$temp1");

# Free from memory
undef($temp1);
undef($temp2);
undef($temp3);

print "\nYour PROXY_PASS is: ".$hash."\n";
print "--------------------------------------------------\n";
print "Please copy this value to your .conf file.\n";
print "The priviledged of your .conf file should be 700\!\n";
print "\n";

undef($hash);
