Creating an MD5 hash
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Creating an MD5 hash




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Creating an MD5 hash  
Carsten Maul


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 10:54 PM

Hi,


I want to generate an MD5 checksum with crypt.h, installed OS Debian Woody.
Unfortunately I only get DES hashes with

strncpy(salt, row[0], 12);
salt[12] = '\0';
encryptedPass = crypt(passwd, salt);
free(salt);

Later I compare the two:

if (!strcmp(row[0], encryptedPass))

row[0] looks like that: $1$mYV0L3j8$nUUWy09JYrzdXurr92ywv1

salt starts with $1$ to indicate that I want an MD5 hash.

Unfortunately the encryptedPass looks like that:
1ba49f4d1ff0f49c

What am I doing wrong ? Did I forget anything ?

Thanks






[ Post a follow-up to this message ]



    Re: Creating an MD5 hash  
Casper H.S. Dik


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 10:54 PM

Carsten Maul <carsten_maul@gmx.de> writes:

>I want to generate an MD5 checksum with crypt.h, installed OS Debian Woody.
>Unfortunately I only get DES hashes with

>strncpy(salt, row[0], 12);
>salt[12] = '\0';
>encryptedPass = crypt(passwd, salt);
>free(salt);

Typical use is:

crypt(passwd, row[0]);

i.e., pass the entire encrypted password in as salt.

That makes your code portable to different algorithms.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.





[ Post a follow-up to this message ]



    Re: Creating an MD5 hash  
James Antill


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-24-04 10:51 PM

On Thu, 23 Sep 2004 16:40:56 +0200, Carsten Maul wrote:

> Hi,
>
>
> I want to generate an MD5 checksum with crypt.h, installed OS Debian Woody
.
> Unfortunately I only get DES hashes with
>
> strncpy(salt, row[0], 12);
> salt[12] = '\0';

> row[0] looks like that: $1$mYV0L3j8$nUUWy09JYrzdXurr92ywv1
>
> salt starts with $1$ to indicate that I want an MD5 hash.

You need at least "$1$mYV0L3j8$" which is bigger than 11 characters. And
as casper said, the second argument should be const char * ... so you
don't need the copy.

--
James Antill -- james@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:55 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register