diff --git a/soap/customerportal.php b/soap/customerportal.php
index 12d8f47fecd62df1d911f9278bee447d8389790d..6e4748f7f63ff8406f301d6e1f3d86793c5864eb 100755
--- a/soap/customerportal.php
+++ b/soap/customerportal.php
@@ -1016,7 +1016,7 @@ function authenticate_user($username,$password,$version,$login = 'true')
 	$customerid = null;
 	for ($i = 0; $i < $num_rows; ++$i) {
 		$customerid = $adb->query_result($result, $i,'id');
-		if (Vtiger_Function::compareEncryptedPassword($password, $adb->query_result($result, $i, 'id'), $adb->query_result($result, $i, 'cryptmode'))) {
+		if (Vtiger_Functions::compareEncryptedPassword($password, $adb->query_result($result, $i, 'user_password'), $adb->query_result($result, $i, 'cryptmode'))) {
 			break;
 		} else {
 			$customerid = null;
@@ -1027,7 +1027,7 @@ function authenticate_user($username,$password,$version,$login = 'true')
 
 	$list[0]['id'] = $customerid;
 	$list[0]['user_name'] = $adb->query_result($result,0,'user_name');
-	$list[0]['user_password'] = $adb->query_result($result,0,'user_password');
+	$list[0]['user_password'] = $password;
 	$list[0]['last_login_time'] = $adb->query_result($result,0,'last_login_time');
 	$list[0]['support_start_date'] = $adb->query_result($result,0,'support_start_date');
 	$list[0]['support_end_date'] = $adb->query_result($result,0,'support_end_date');
diff --git a/vtlib/Vtiger/Functions.php b/vtlib/Vtiger/Functions.php
index f0b1c66023afc4075a7c140f85c8e9ecb81121a8..67d11f7d647295710420e2b516c4fe8fb9b981e6 100644
--- a/vtlib/Vtiger/Functions.php
+++ b/vtlib/Vtiger/Functions.php
@@ -998,8 +998,8 @@ class Vtiger_Functions {
 		$reEncryptedPassword = null;
 		switch ($mode) {
 			case 'CRYPT': $reEncryptedPassword = crypt($plainText, $encryptedPassword); break;
-			case 'MD5'  : $reEncryptedPassword = md5($plainText);
-			default     : $reEncryptedPassword = $plainText;
+			case 'MD5'  : $reEncryptedPassword = md5($plainText);	break;
+			default     : $reEncryptedPassword = $plainText;		break;
 		}
 		return ($reEncryptedPassword == $encryptedPassword);
 	}