Fix time parameter with new machine number
refactoring
This commit is contained in:
@@ -1274,17 +1274,13 @@ namespace Step.NC
|
||||
// Check if machine number contains letters
|
||||
bool containsLetters = Regex.IsMatch(strMachNumber, @".*?[a-zA-Z].*?");
|
||||
int machNumber = 0;
|
||||
|
||||
if (containsLetters)
|
||||
{
|
||||
// Convert ASCII string to a single INT
|
||||
for (int i = 1; i <= strMachNumber.Count(); i++)
|
||||
machNumber += strMachNumber[strMachNumber.Count() - i] << (8 * (i - 1));
|
||||
}
|
||||
machNumber = SupportFunctions.ConvertAsciiStringToInt(strMachNumber);
|
||||
else
|
||||
{
|
||||
// Convert string of digits to a INT
|
||||
machNumber = int.Parse(strMachNumber);
|
||||
}
|
||||
|
||||
// Read Data from NC & elaborate it
|
||||
long NcCandy = 0;
|
||||
|
||||
@@ -64,10 +64,10 @@ namespace Step.UI
|
||||
if (psw == "cmsserviceonly")
|
||||
bValid = true;
|
||||
|
||||
else if (Utils.CandiesController.LincensePasswordDecode(psw, out string Matr, out int Command, out long Parameter))
|
||||
else if (Utils.CandiesController.LincensePasswordDecode(psw, out string MatricolaString, out int MatricolaNumerica, out int Command, out long Parameter))
|
||||
|
||||
//Controllo la matricola
|
||||
if (this.Matricola != Matr.ToString())
|
||||
if (this.Matricola != MatricolaString)
|
||||
bValid = false;
|
||||
else
|
||||
{
|
||||
@@ -81,7 +81,7 @@ namespace Step.UI
|
||||
if(Nc != null)
|
||||
{
|
||||
Licenza = new DateTime(Parameter * TimeSpan.TicksPerDay);
|
||||
Nc.WriteCandy(Licenza, Int32.Parse(Matricola));
|
||||
Nc.WriteCandy(Licenza, MatricolaNumerica);
|
||||
bValid = false;
|
||||
}
|
||||
break;
|
||||
@@ -91,7 +91,7 @@ namespace Step.UI
|
||||
if (Nc != null)
|
||||
{
|
||||
Licenza = new DateTime(0);
|
||||
Nc.WriteCandy(Licenza, Int32.Parse(Matricola));
|
||||
Nc.WriteCandy(Licenza, MatricolaNumerica);
|
||||
bValid = false;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -26,51 +26,56 @@ namespace Step.Utils
|
||||
#region PUBLIC_METHODS
|
||||
|
||||
// Decodifica password esportando i dati. Ereditata da CMS-Control
|
||||
public static bool LincensePasswordDecode(String Password, out string Matricola, out int Command, out long Parameter)
|
||||
public static bool LincensePasswordDecode(String Password, out string Matricola, out int MatricolaNumerica, out int Command, out long Parameter)
|
||||
{
|
||||
String szVal;
|
||||
String decryptedString;
|
||||
int nChk = 0;
|
||||
|
||||
Matricola = "";
|
||||
MatricolaNumerica = 0;
|
||||
Command = 0;
|
||||
Parameter = 0;
|
||||
|
||||
try
|
||||
{
|
||||
szVal = AlgoritmoService_Back(Password).ToString();
|
||||
decryptedString = AlgoritmoService_Back(Password).ToString();
|
||||
|
||||
for (int i = 0; i <= szVal.Length - 1 - 1; i++)
|
||||
for (int i = 0; i <= decryptedString.Length - 1 - 1; i++)
|
||||
{
|
||||
nChk += (int)char.GetNumericValue(szVal[i]);
|
||||
nChk += (int)char.GetNumericValue(decryptedString[i]);
|
||||
}
|
||||
|
||||
//inserita password con checksum errato
|
||||
if (szVal.Last() != nChk.ToString().Last())
|
||||
if (decryptedString.Last() != nChk.ToString().Last())
|
||||
return false;
|
||||
|
||||
if(szVal.Count() > 13)
|
||||
int indexParameterOffset = 6;
|
||||
|
||||
if(decryptedString.Count() > 13)
|
||||
{
|
||||
var machinNumberString = szVal.Substring(1, 11);
|
||||
// If decrypted string has more than 13 characters means that the machine number contains a letter
|
||||
var machinNumberString = decryptedString.Substring(1, 11);
|
||||
|
||||
int intValue = Int32.Parse(machinNumberString);
|
||||
|
||||
for (int i = 3; i >= 0; i--)
|
||||
{
|
||||
Matricola += (char)((byte)(intValue >> (8 * i)));
|
||||
}
|
||||
MatricolaNumerica = int.Parse(machinNumberString);
|
||||
// Convert machineNumber from int to ascii
|
||||
Matricola = SupportFunctions.ConvertIntToAsciiString(MatricolaNumerica);
|
||||
// Change the offset of the parameter
|
||||
indexParameterOffset = 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
Matricola = szVal.Substring(1, 5);
|
||||
Matricola = decryptedString.Substring(1, 5);
|
||||
MatricolaNumerica = Int32.Parse(Matricola);
|
||||
}
|
||||
|
||||
Command = Int16.Parse(szVal.Substring(0, 1));
|
||||
Parameter = long.Parse(szVal.Substring(6, szVal.Length - 6 - 1));
|
||||
Command = short.Parse(decryptedString.Substring(0, 1));
|
||||
Parameter = long.Parse(decryptedString.Substring(indexParameterOffset, decryptedString.Length - indexParameterOffset - 1));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -473,6 +473,26 @@ namespace Step.Utils
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string ConvertIntToAsciiString(int integer)
|
||||
{
|
||||
string outputString = "";
|
||||
for (int i = 3; i >= 0; i--)
|
||||
{
|
||||
outputString += (char)((byte)(integer >> (8 * i)));
|
||||
}
|
||||
|
||||
return outputString;
|
||||
}
|
||||
|
||||
public static int ConvertAsciiStringToInt(string asciiString)
|
||||
{
|
||||
int number = 0;
|
||||
for (int i = 1; i <= asciiString.Count(); i++)
|
||||
number += asciiString[asciiString.Count() - i] << (8 * (i - 1));
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
//----- Chipher Private Class ---------------------------------
|
||||
#region Chipher_Private_Class
|
||||
|
||||
@@ -574,8 +594,4 @@ namespace Step.Utils
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user