Click here to Skip to main content
15,891,253 members
Articles / Programming Languages / C#

Unix md5crypt

Rate me:
Please Sign up or sign in to vote.
4.50/5 (4 votes)
5 Oct 2007CPOL 32.4K   645   18  
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.

C#
        /// <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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Spain Spain
Born in Valencia (Spain). Agricultural engineer, informatics engineer.
Keen on drinking wine & beer and travelling.(original isn't it)
Actually teaching in high-school an wasting a significative part of my life in programming with the .NET.

Comments and Discussions

 
-- There are no messages in this forum --