@@ -112,17 +112,47 @@
 	}
 }
 
+unsigned char decode_char(char x) {
+	if (x >= '0' && x <= '9')
+		return (x - 0x30);
+	else if (x >= 'A' && x <= 'F')
+		return(x - 0x37);
+	else if (x >= 'a' && x <= 'f')
+		return(x - 0x57);
+	else {
+		fprintf(stderr,"%s:%d:%s(): [ERROR in libmariadbclient]: \n",  __FILE__, __LINE__, __func__);
+		return 0;
+	}
+}
+
+void unhex_pass(unsigned char *out, const char *in) {
+	int i=0;
+	for (i=0;i<SHA1_MAX_LENGTH;i++) {
+		// this can be simplified a lot, but leaving like this to make it easy to debug
+		unsigned char c=0, d=0;
+		c=decode_char(in[i*2]);
+		c=(c*16) & 0xF0;
+		d=decode_char(in[i*2+1]);
+		d=d & 0x0F;
+		c+=d;
+		out[i]=c;
+	}
+}
+
 void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password)
 {
 	MYSQL_SHA1_CTX context;
 	unsigned char sha1[SHA1_MAX_LENGTH];
 	unsigned char sha2[SHA1_MAX_LENGTH];
 	
-
-	/* Phase 1: hash password */
-	MYSQL_SHA1Init(&context);
-	MYSQL_SHA1Update(&context, (unsigned char *)password, strlen((char *)password));
-	MYSQL_SHA1Final(sha1, &context);
+	if (password[0]=='*') {
+		unhex_pass(sha1,password+1);
+	} else {
+		/* Phase 1: hash password */
+		MYSQL_SHA1Init(&context);
+		MYSQL_SHA1Update(&context, (unsigned char *)password, strlen((char *)password));
+		MYSQL_SHA1Final(sha1, &context);
+	}
 
 	/* Phase 2: hash sha1 */
 	MYSQL_SHA1Init(&context);
