2 ** Copyright 2001-2008 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
9 #include "courierauthsasl.h"
15 #include "sha1/sha1.h"
18 static const char rcsid
[]="$Id: checkpasswordsha1.c,v 1.7 2008/12/25 14:52:38 mrsam Exp $";
20 int authcheckpasswordsha1(const char *password
, const char *encrypted_password
)
22 if (strncasecmp(encrypted_password
, "{SHA}", 5) == 0)
24 return (strcmp(encrypted_password
+5, sha1_hash(password
)));
26 if (strncasecmp(encrypted_password
, "{SHA256}", 8) == 0)
28 return (strcmp(encrypted_password
+8, sha256_hash(password
)));
30 if (strncasecmp(encrypted_password
, "{SHA512}", 8) == 0)
32 return (strcmp(encrypted_password
+8, sha512_hash(password
)));
34 if (strncasecmp(encrypted_password
, "{SSHA}", 6) == 0)
40 code
= strdup(encrypted_password
+6);
47 i
= authsasl_frombase64(code
);
49 if(i
== -1 || i
< sizeof(SSHA_RAND
))
55 memcpy((char *)rand
, code
+i
-sizeof(SSHA_RAND
),
58 i
=strcmp(encrypted_password
+6, ssha_hash(password
, rand
));