diff options
| author | ulim <a.sporto+bee@gmail.com> | 2008-04-14 15:10:53 +0200 | 
|---|---|---|
| committer | ulim <a.sporto+bee@gmail.com> | 2008-04-14 15:10:53 +0200 | 
| commit | b79308b943149d729b1daea8c56cff9fc02711a0 (patch) | |
| tree | a5f80445ed63d864703941474dc6cf8998df3136 /lib/misc.c | |
| parent | 6cac643f6933e431b90fcb937dec505f989e6a53 (diff) | |
| parent | aa311173a85020bcbbbf61135a5451e171d422f5 (diff) | |
merged in upstream r379 (somewhere after 1.2-3).
Just one trivial conflict in the jabber Makefile, went smoothly.
Diffstat (limited to 'lib/misc.c')
| -rw-r--r-- | lib/misc.c | 41 | 
1 files changed, 41 insertions, 0 deletions
| @@ -32,6 +32,7 @@  #define BITLBEE_CORE  #include "nogaim.h" +#include "base64.h"  #include <stdio.h>  #include <stdlib.h>  #include <string.h> @@ -596,3 +597,43 @@ gboolean ssl_sockerr_again( void *ssl )  	else  		return sockerr_again();  } + +/* Returns values: -1 == Failure (base64-decoded to something unexpected) +                    0 == Okay +                    1 == Password doesn't match the hash. */ +int md5_verify_password( char *password, char *hash ) +{ +	md5_byte_t *pass_dec = NULL; +	md5_byte_t pass_md5[16]; +	md5_state_t md5_state; +	int ret, i; +	 +	if( base64_decode( hash, &pass_dec ) != 21 ) +	{ +		ret = -1; +	} +	else +	{ +		md5_init( &md5_state ); +		md5_append( &md5_state, (md5_byte_t*) password, strlen( password ) ); +		md5_append( &md5_state, (md5_byte_t*) pass_dec + 16, 5 ); /* Hmmm, salt! */ +		md5_finish( &md5_state, pass_md5 ); +		 +		for( i = 0; i < 16; i ++ ) +		{ +			if( pass_dec[i] != pass_md5[i] ) +			{ +				ret = 1; +				break; +			} +		} +		 +		/* If we reached the end of the loop, it was a match! */ +		if( i == 16 ) +			ret = 0; +	} +	 +	g_free( pass_dec ); + +	return ret; +} | 
