Click here to Skip to main content
Click here to Skip to main content

Unix md5crypt

By , 5 Oct 2007
 

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

License

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

About the Author

MartinSon
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130617.1 | Last Updated 5 Oct 2007
Article Copyright 2007 by MartinSon
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid