Unix md5crypt
The MD5 shadow password
Introduction
I was looking for an 'algo' to prepare the encrypted password of the shadow file of a Linux box. I need to prepare 600 hundred accounts and the local authentication is fast and reliable.
Background
Get ready, because if you want to understand the base of this 'algo', you will have to find out in standards of cryptography mainly MD5.
So I got the code from others and translated:
# 0423.2000 by michal wallace http://www.sabren.com/
# based on perl's Crypt::PasswdMD5 by Luis Munoz (lem@cantv.net)
# based on /usr/src/libcrypt/crypt.c from FreeBSD 2.2.5-RELEASE
#
# MANY THANKS TO
#
# Carey Evans - http://home.clear.net.nz/pages/c.evans/
# Dennis Marti - http://users.starpower.net/marti1/
You do it like this ...
use Authen::Passphrase::MD5Crypt;
$ppr = Authen::Passphrase::MD5Crypt->new(
salt => "Vd3f8aG6",
hash_base64 => "GcsdF4YCXb0PM2UmXjIoI1");
... but no translators from this code to C# or VB.
Using the Code
It's easy, think in a mixing key (salt or pepper) and crypt will mix it with the password.
/// <summary>
/// Unix-like Crypt-MD5 function
/// </summary>
/// <param name="password">The user password</param>
/// <param name="salt">The salt or the pepper of the password</param>
/// <returns>a human readable string</returns>
public static String crypt(String password, String salt)
...
MD5Crypt.crypt("cat","hat") = $1$hat$aIZAkAKuZS4bQQyEO56ER/
History
- 5th October, 2007: Initial post