Changeset 4e8db1c for lib


Ignore:
Timestamp:
2008-03-16T16:03:52Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
ec0355f
Parents:
50d26f3
Message:

Moved password hash verification to md5_verify_password() so this can be
reused for IRC/OPER passwords (to have encrypted in bitlbee.conf).

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/misc.c

    r50d26f3 r4e8db1c  
    3333#define BITLBEE_CORE
    3434#include "nogaim.h"
     35#include "base64.h"
    3536#include <stdio.h>
    3637#include <stdlib.h>
     
    597598                return sockerr_again();
    598599}
     600
     601/* Returns values: -1 == Failure (base64-decoded to something unexpected)
     602                    0 == Okay
     603                    1 == Password doesn't match the hash. */
     604int md5_verify_password( char *password, char *hash )
     605{
     606        md5_byte_t *pass_dec = NULL;
     607        md5_byte_t pass_md5[16];
     608        md5_state_t md5_state;
     609        int ret, i;
     610       
     611        if( base64_decode( hash, &pass_dec ) != 21 )
     612        {
     613                ret = -1;
     614        }
     615        else
     616        {
     617                md5_init( &md5_state );
     618                md5_append( &md5_state, (md5_byte_t*) password, strlen( password ) );
     619                md5_append( &md5_state, (md5_byte_t*) pass_dec + 16, 5 ); /* Hmmm, salt! */
     620                md5_finish( &md5_state, pass_md5 );
     621               
     622                for( i = 0; i < 16; i ++ )
     623                {
     624                        if( pass_dec[i] != pass_md5[i] )
     625                        {
     626                                ret = 1;
     627                                break;
     628                        }
     629                }
     630               
     631                /* If we reached the end of the loop, it was a match! */
     632                if( i == 16 )
     633                        ret = 0;
     634        }
     635       
     636        g_free( pass_dec );
     637
     638        return ret;
     639}
  • lib/misc.h

    r50d26f3 r4e8db1c  
    6767G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl );
    6868
     69G_MODULE_EXPORT int md5_verify_password( char *password, char *hash );
     70
    6971#endif
Note: See TracChangeset for help on using the changeset viewer.