public static bool UpdateLastActive(AuthData data) { Keys keys = GetKeys(); if (data != null && keys != null && keys.Public.Equals(data.PublicKey)) { var privateKey = keys.Private; var hashCheck = General.Sha1Hash(data.Data + privateKey + data.PublicKey); if (hashCheck.Equals(data.Hash)) { //var newToken = General.Sha1Hash(privateKey + hashCheck + GetDateTimeFormatted()); var computerData = new ComputerData() { Name = data.HostName, IpExternal = data.IpExternal, IpInternal = data.IpInternal, LastActive = DateTime.Now, FileUploaded = null, BytesUploaded = 0, Hash = null }; computerData.Hash = Transmitter.GetComputerHash(computerData); return(UpdateLastActive(computerData.Hash)); } } else { if (data != null && !string.IsNullOrEmpty(data.Hash)) { return(UpdateLastActive(data.Hash)); } } return(false); }
public static string GetComputerHash(string computerName) { var data = JsonConvert.DeserializeObject <List <ComputerData> >(GetFileContents("~/App_Data", "computers.json")); var computer = data.Where(c => c.Name == computerName).FirstOrDefault(); if (computer != null) { return(Transmitter.GetComputerHash(computer)); } return(null); }
private static ComputerData GetComputerData(AuthData data) { ComputerData computerData = null; if (data != null) { computerData = new ComputerData() { Name = data.HostName, IpExternal = data.IpExternal, IpInternal = data.IpInternal, LastActive = DateTime.Now, FileUploaded = null, BytesUploaded = 0, Hash = null, IsOnline = false }; // hash value needs to be calculated after constructor computerData.Hash = Transmitter.GetComputerHash(computerData); } return(computerData); }