diff --git a/client/connect_test.c b/client/connect_test.c
index fd81ad635adb65cae5c0f689262e95e348bc8b8a..e19f83dac92929db3c45342e846f24bb375eb1cf 100644
--- a/client/connect_test.c
+++ b/client/connect_test.c
@@ -16,6 +16,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include "my_global.h"
 #include "mysql.h"
 
 static void change_user(MYSQL *sock,const char *user, const char *password,
diff --git a/include/mysql_com.h b/include/mysql_com.h
index de3f93c01d1bb48966e3354051853cf6616c063a..68ea550c76833a367980452a0c25d3d6d2983aae 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -281,8 +281,8 @@ void randominit(struct rand_struct *,unsigned long seed1,
 		unsigned long seed2);
 double rnd(struct rand_struct *);
 void make_scrambled_password(char *to,const char *password,my_bool force_old_scramble,struct rand_struct *rand_st);
-uint get_password_length(my_bool force_old_scramble);
-uint8 get_password_version(const char* password);
+int get_password_length(my_bool force_old_scramble);
+char get_password_version(const char* password);
 void create_random_string(int length,struct rand_struct *rand_st,char* target);
 my_bool validate_password(const char* password, const char* message, ulong* salt);
 void password_hash_stage1(char *to, const char *password);
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index dab983353a069f852d8553547b95d86cc94c24b2..748642c6aa2cb70cbcf872705abadfc305dab32c 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -70,6 +70,7 @@ char* query_table_status(THD *thd,const char *db,const char *table_name);
 #define ACL_CACHE_SIZE		256
 /* Password lengh for 4.1 version previous versions had 16 bytes password hash */
 #define HASH_PASSWORD_LENGTH	45
+#define HASH_OLD_PASSWORD_LENGTH 16
 #define HOST_CACHE_SIZE		128
 #define MAX_ACCEPT_RETRY	10	// Test accept this many times
 #define MAX_FIELDS_BEFORE_HASH	32
diff --git a/sql/password.c b/sql/password.c
index 13f8d593da622981259495dc6c3667494a378ec9..b9eb60123545b799c7384f4203f89526c2abd2d5 100644
--- a/sql/password.c
+++ b/sql/password.c
@@ -232,7 +232,7 @@ void hash_password(ulong *result, const char *password)
     none
 */
 
-inline void password_hash_stage1(char *to, const char *password)
+void password_hash_stage1(char *to, const char *password)
 {
   SHA1_CONTEXT context; 
   sha1_reset(&context);
@@ -259,7 +259,7 @@ inline void password_hash_stage1(char *to, const char *password)
     none
 */
 
-inline void password_hash_stage2(char *to,const char *salt)
+void password_hash_stage2(char *to,const char *salt)
 {
   SHA1_CONTEXT context;     
   sha1_reset(&context);
@@ -398,7 +398,7 @@ my_bool validate_password(const char* password, const char* message, ulong* salt
     password length >0
 */
 
-inline uint get_password_length(my_bool force_old_scramble)
+inline int get_password_length(my_bool force_old_scramble)
 {
   if (force_old_scramble)
     return 16;
@@ -418,7 +418,7 @@ inline uint get_password_length(my_bool force_old_scramble)
    !0 password version char for newer passwords
 */
 
-inline uint8 get_password_version(const char* password)
+inline char get_password_version(const char* password)
 {
   if (password==NULL) return 0;
   if (password[0]==PVERSION41_CHAR) return PVERSION41_CHAR;
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index a5fb24b079678c9cfc00a8fa108b3fd3f2264d9d..d4ca8ed1bc7216c5b718d88024273e54d64263df 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -732,8 +732,11 @@ static void acl_update_user(const char *user, const char *host,
 	}
 	if (password)
 	{
-	  if (!password[0])
+	  if (!password[0]) /* If password is empty set it to null */
+          {
 	    acl_user->password=0;
+            acl_user->pversion=0; // just initialize 
+          }    
 	  else
 	  {
 	    acl_user->password=(char*) "";	// Just point at something
@@ -774,7 +777,7 @@ static void acl_insert_user(const char *user, const char *host,
   {
     acl_user.password=(char*) "";		// Just point at something
     get_salt_from_password(acl_user.salt,password);
-    acl_user.pversion=get_password_version(acl_user.password);
+    acl_user.pversion=get_password_version(password);
   }
 
   VOID(push_dynamic(&acl_users,(gptr) &acl_user));
@@ -1337,14 +1340,15 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
 
   if (combo.password.str && combo.password.str[0])
   {
-    if (combo.password.length != HASH_PASSWORD_LENGTH)
+    if ((combo.password.length != HASH_PASSWORD_LENGTH) 
+         && combo.password.length != HASH_OLD_PASSWORD_LENGTH)
     {
       my_error(ER_PASSWORD_NO_MATCH,MYF(0));
       DBUG_RETURN(-1);
     }
     password=combo.password.str;
   }
-
+  
   table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
   table->field[1]->store(combo.user.str,combo.user.length, system_charset_info);
   table->file->index_init(0);