#!/usr/bin/perl

use CGI;
my $q   = new CGI;
my %in  = $q->Vars;

#use Digest::MD5 qw(md5 md5_hex md5_base64);
#use Crypt::PasswdMD5; 

#print unix_md5_crypt("Password", "Salt");

#use Encode qw(encode_utf8);


print "Content-type: text/html\n\n";
print "<html>\n";


&form;

if ($in{'password'}){
	&encryptpasswd;
}


if ($in{'moreinfo'}){
	&environ;
}

sub form {
        print "<br><br><center><table cellspacing=2 cellpadding=3 border=1 bgcolor=\"#ffffff\" >\n";
        print "<FORM method=POST>\n";

        print "<td>Create an MD5 hash of a string:</td><td class=GOED><input type=\"text\" size=\"50\" maxlength=\"50\" name=\"password\" value=\"$in{'password'}\"></td>"; 
	print "<td>Extra info?</td><td><input type=\"checkbox\" name=moreinfo value=Checked $in{'moreinfo'}></td>";

	print "<td><input type=\"submit\" name=\"submit\" value = 'Search'></td></tr>\n";
        print "</form></table></center>\n\n";

	print "<center><table cellspacing=2 cellpadding=3 border=1 bgcolor=\"#ffffff\"><tr><td>MD5 is not very safe... check this decrypt site: <a href=https://hashkiller.co.uk/Cracker/MD5>md5 cracker</a></td></tr></table></center>";
}

sub encryptpasswd {
	my $encrpass = unix_md5_crypt($in{'password'}, "Salt");
	#my $encrpass = md5_hex($in{'password'});
	print "<br><r><center>md5 passwd = <b>$encrpass</b></center>";
}

sub environ {
	print "<pre>\n";
	#foreach $key (sort keys(%ENV)) {
	#	print "$key = $ENV{$key}<p>";
	#}
	#
	#print "</pre>\n";

	print "<center><table width=50% border=1><tr><td>This MD5 hash generator is useful for encoding passwords, credit cards numbers and other sensitive date into MySQL, Postgress or other databases. PHP programmers, ASP programmers and anyone developing on MySQL, SQL, Postgress or similar should find this online tool an especially handy resource.

What is an MD5 hash?
An MD5 hash is created by taking a string of an any length and encoding it into a 128-bit fingerprint. Encoding the same string using the MD5 algorithm will always result in the same 128-bit hash output. MD5 hashes are commonly used with smaller strings when storing passwords, credit card numbers or other sensitive data in databases such as the popular MySQL. This tool provides a quick and easy way to encode an MD5 hash from a simple string of up to 256 characters in length.

MD5 hashes are also used to ensure the data integrity of files. Because the MD5 hash algorithm always produces the same output for the same given input, users can compare a hash of the source file with a newly created hash of the destination file to check that it is intact and unmodified.

An MD5 hash is NOT encryption. It is simply a fingerprint of the given input. However, it is a one-way transaction and as such it is almost impossible to reverse engineer an MD5 hash to retrieve the original string.</td></tr></table></center>\n";

}
