Amir Malik (amir@virusexperts.com) Webmaster
That number is considered to be unique to that piece of data, and it is practically impossible to have that algorithm produce the same number for another piece of data. By "practically impossible," it is meant that the probability of two pieces of data having the same unique number (hash) as a result is highly unlikely, although this depends completely on the hasing algorithm used. For example, MD5 is a 128-bit hashing algorithm, and it can produce at most 2128 unique hashes for any given pieces of data. Even though that is a large number, what if we feed the algorithm 2128 + 1 different pieces of data? Surely we will find that at least two hashes will be the same. However, the time it would take to check every single piece of data, is far too great, even with modern supercomputers.
The newer shadow format uses MD5 as the hashing algorithm.
root:$1$e8aD.GAJ$RVs8vl4KaXt/hr2pLAHjc.:12515:0:99999:7:::But then again, you may see a shorter line for the same password.
root:Ep6mckrOLChF.:12515:0:99999:7:::So what? Well, if you know your shadow file fields, you'll know that the first field is the login name of the user. The next field is a hash of the user's password. The rest of the fields deal with password aging and expiry. Take a close look at the second field. In the first snippet, we have a long hash -- yes, this is indeed an MD5 hash of the password. The latter snippet is a vanilla DES-based hash. As a programmer, how do we differentiate between these two types of hashes? Historically, the DES hash uses the Unix system call crypt() to create the hash from a password and a random seed value (referred to as a salt). This random seed value is usually composed of two characters (letters, numbers, or both) and is chosen randomly. The rest of the field (minus the salt) consists of the hashed password.
Now let's take a look at the first snippet again. You will notice it begins with $1$. This indicates that this is a password hashed using the MD5 algorithm. The 8 characters following the second dollar sign compose the salt. Note that this is much larger than the two characters allocated for a plain DES-based hash. Obviously, this allows for a more random hash value. Following the salt, is the actual hash of the password.
Now that you know the format of the field, you'll surely want to generate some hashed MD5 passwords. To create an MD5 shadow password, you will need to:
use Crypt::PasswdMD5;
chomp(my $password = <STDIN>);
chomp(my $salt = <STDIN>);
$crypted = unix_md5_crypt($password, $salt);
print "$crypted\n";
See Also
Resources