private Boolean CheckPINCode(String strPIN, char charMaxDigit, ref String errorMessage)
{
int testPin;
Log.Debug("strPIN=" + strPIN + " strMaxDigit=" + charMaxDigit);
if (strPIN.Length == 0)
{
errorMessage = "PIN cannot be empty";
return false;
}
if (!Int32.TryParse(strPIN, out testPin))
{
errorMessage = "PIN contains non-numeric characters";
return false;
}
// wrong length
if ((strPIN.Length < MinPinLength) || (strPIN.Length > MaxPinLength))
{
errorMessage = "PIN length has to be between " + MinPinLength + " and " + MaxPinLength + " digits";
return false;
}
// pin is out of fange
for (byte i = 0; i < strPIN.Length; i++)
{
Log.Debug("strPIN[i]=" + (strPIN[i] - '0') + " charMaxDigit=" + (charMaxDigit - '0'));
if ((strPIN[i] - '0') > (charMaxDigit - '0'))
{
errorMessage = "PIN has digits outside of the valid range";
return false;
}
}
Log.Debug("pin is valid!");
return true;
}