ACAT.Extensions.Default.UI.Dialogs.ScreenLockSettingsForm.CheckPINCode C# (CSharp) Method

CheckPINCode() private method

Validates the pin entered so far to make sure it is all digits, is within the length specified
private CheckPINCode ( String strPIN, char charMaxDigit, String &errorMessage ) : Boolean
strPIN String The Pin
charMaxDigit char max length of the pin
errorMessage String error message if not valid
return Boolean
        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;
        }