Click here to Skip to main content
13,139,254 members (91,061 online)
Click here to Skip to main content
Add your own
alternative version

Stats

21.6K views
474 downloads
18 bookmarked
Posted 5 Oct 2007

Unix md5crypt

, 5 Oct 2007
Rate this:
Please Sign up or sign in to vote.
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

License

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

Share

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.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 5 Oct 2007
Article Copyright 2007 by MartinSon
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid