void Login(NewCamdMessage message) { string username; string encryptedPassword; try { const int header = 3; var splitter = Array.IndexOf(message.Data, (byte)0, header); username = Encoding.ASCII.GetString(message.Data.Skip(header).Take(splitter - header).ToArray()); splitter++; encryptedPassword = Encoding.ASCII.GetString(message.Data.Skip(splitter).Take(message.Data.Length - splitter - 1).ToArray()); } catch (Exception ex) { _logger.Warn($"Couldn't read the login credentials from {Name}"); _logger.Debug("Exception at login", ex); Dispose(); return; } var expectedPassword = _crypto.UnixEncrypt(_settings.Password, "$1$abcdefgh$"); var loginValid = _settings.Username.Equals(username) && expectedPassword.Equals(encryptedPassword); message.Type = loginValid ? NewCamdMessageType.MsgClient2ServerLoginAck : NewCamdMessageType.MsgClient2ServerLoginNak; _logger.Info($"{Name} - Login is {message.Type}"); message.Data = new byte[3]; _communication.SendMessage("Login response", message); if (!loginValid) { return; } _communication.UpdateKeyBlock(encryptedPassword); }