Return error for password length bit mismatch

Return InvalidLength error, for password length bit mismatch
for Set User Password command. i.e. if length is specified as 16
then accept only 16 byte charachers and for length specified as 20
accept 20 byte characters

Unit-test:
1. Verified both by issuing proper 20 & 16 byte length filed
2. Also verified error sending 20 character byte by setting 16
byte length

Change-Id: I1e6cca3b4dcd920e8e8dfcf23344c10d1bf37ca2
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/user_channel/usercommands.cpp b/user_channel/usercommands.cpp
index d901e2c..eb770e4 100644
--- a/user_channel/usercommands.cpp
+++ b/user_channel/usercommands.cpp
@@ -37,6 +37,8 @@
 static constexpr uint8_t enableUser = 0x01;
 static constexpr uint8_t setPassword = 0x02;
 static constexpr uint8_t testPassword = 0x03;
+static constexpr uint8_t passwordKeySize20 = 1;
+static constexpr uint8_t passwordKeySize16 = 0;
 
 /** @struct SetUserAccessReq
  *
@@ -432,9 +434,12 @@
         return IPMI_CC_REQ_DATA_LEN_INVALID;
     }
     // If set / test password then password length has to be 16 or 20 bytes
+    // based on the password size bit.
     if (((req->operation == setPassword) || (req->operation == testPassword)) &&
-        ((passwordLength != maxIpmi20PasswordSize) &&
-         (passwordLength != maxIpmi15PasswordSize)))
+        (((req->ipmi20 == passwordKeySize20) &&
+          (passwordLength != maxIpmi20PasswordSize)) ||
+         ((req->ipmi20 == passwordKeySize16) &&
+          (passwordLength != maxIpmi15PasswordSize))))
     {
         log<level::DEBUG>("Invalid Length");
         return IPMI_CC_REQ_DATA_LEN_INVALID;