aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2008-03-16 16:03:52 +0000
committerWilmer van der Gaast <wilmer@gaast.net>2008-03-16 16:03:52 +0000
commit4e8db1c0141f74dc6156a57739613483344b358d (patch)
tree4a0dbad1ddf9c41cac3961a7ddd14573b2bb0b4e /lib
parent50d26f33935aadc556dd3e79829b1ca01bbceab9 (diff)
Moved password hash verification to md5_verify_password() so this can be
reused for IRC/OPER passwords (to have encrypted in bitlbee.conf).
Diffstat (limited to 'lib')
-rw-r--r--lib/misc.c41
-rw-r--r--lib/misc.h2
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/misc.c b/lib/misc.c
index 18d98f9e..ccf208b5 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -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;
+}
diff --git a/lib/misc.h b/lib/misc.h
index 7804bfb1..a2acada6 100644
--- a/lib/misc.h
+++ b/lib/misc.h
@@ -66,4 +66,6 @@ G_MODULE_EXPORT char *word_wrap( char *msg, int line_len );
G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl );
+G_MODULE_EXPORT int md5_verify_password( char *password, char *hash );
+
#endif