WIP maintenances with password

Fix Siemens library
This commit is contained in:
Lucio Maranta
2019-03-04 17:23:13 +01:00
parent 28b6932ee2
commit 321f6bd9e0
7 changed files with 92 additions and 22 deletions
@@ -70,7 +70,7 @@ namespace Step.Database.Controllers
.Where(x => x.MachineId == machineId && x.UserId == userId) // Find by machine id and user id, joining with role
.FirstOrDefault();
if(machineUser != null)
if (machineUser != null)
{
RoleModel role = machineUser.Role;
return new DTORoleModel()
@@ -83,7 +83,6 @@ namespace Step.Database.Controllers
return null;
}
public bool UserIsCmsAdmin(int machineId, int userId)
{
MachineUserModel user = FindByUserId(machineId, userId);
@@ -93,7 +92,6 @@ namespace Step.Database.Controllers
return false;
}
public int CompareUsersRole(int firstUserId, int secondUserId, int machineId)
{
MachineUserModel firstUser = FindByUserId(machineId, firstUserId);
@@ -2,6 +2,7 @@
using Step.Model.DTOModels;
using Step.Model.DTOModels.MaintenanceModels;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity;
using System.IO;
@@ -356,5 +357,75 @@ namespace Step.Database.Controllers
}
#endregion Attachment
private void GetDataFromMaintenancePassword(string password, out int number, out int hours, out int cw)
{
string tmpPassword1 = "",
tmpPassword3 = "",
tmpPassword4 = "",
tmpPassword5 = "";
int controlNumber = 0;
Hashtable htCifrario = new Hashtable
{
{ "K", "0" },
{ "M", "1" },
{ "X", "2" },
{ "N", "3" },
{ "G", "4" },
{ "V", "5" },
{ "P", "6" },
{ "Z", "7" },
{ "H", "8" },
{ "Q", "9" }
};
// Create tmpPassword5 changing characters that matches with characters in the hashtable
foreach (char c in password)
{
if (htCifrario.Contains(c))
tmpPassword5 += htCifrario[c].ToString(); // Change character with hashtable val
else
tmpPassword5 += c;
}
// Get control number
controlNumber = Convert.ToInt32(Right(tmpPassword5, 1));
tmpPassword4 = tmpPassword5.Remove(tmpPassword5.Length - 1);
// Create tmpPassoword3
foreach(char c in tmpPassword4)
{
// If tmpPassword is empty copy the first character
if(tmpPassword3.Length == 0)
{
tmpPassword3 = c.ToString();
}
else
{
// Check if character is a number
if (char.IsNumber(c))
// Add first digit of -> Number + 10 - control number
tmpPassword3 += Right((Convert.ToInt32(c) + 10 - controlNumber).ToString(), 1);
else
tmpPassword3 += c.ToString();
}
}
tmpPassword1 = tmpPassword3.PadLeft(11, '0');
hours = Convert.ToInt32(tmpPassword1.Substring(0, 5), 16); // Convert from hexadecimal
number = Convert.ToInt32(tmpPassword1.Substring(5, 4), 16); // Convert from hexadecimal
cw = Convert.ToInt32(tmpPassword1.Substring(9, 2), 16); // Convert from hexadecimal
}
private static string Right(string value, int size)
{
// if length is greater than "size" resets "size"
size = (value.Length < size ? value.Length : size);
// Substring is the equivalent of VB NET RIGHT
string newValue = value.Substring(value.Length - size);
return newValue;
}
}
}