public static bool CheckPassword(string us, string pw) { try { string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\RemoteHealthcare\DoctorLogin.txt"; string s; using (StreamReader sr = File.OpenText(path)) { s = sr.ReadLine(); while (s != null) { if (TagDecoder.GetValueByTag(Tag.UN, s) == us) { if (TagDecoder.GetValueByTag(Tag.PW, s) == pw) { return(true); } else { return(false); } } s = sr.ReadLine(); } return(us == "admin" && pw == "admin"); } } catch (Exception) { return(us == "admin" && pw == "admin"); } }
public static byte[] Encrypt(string plainText, string key) { byte[] encrypted; byte[] keyBytes = GetKeyBytes(key); FileWriter fileWriter = new FileWriter(); using (AesManaged aes = new AesManaged()) { ICryptoTransform encryptor = aes.CreateEncryptor(keyBytes, IV); using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { using (StreamWriter sw = new StreamWriter(cs)) { sw.Write(plainText); } encrypted = ms.ToArray(); } } } if (TagDecoder.GetValueByTag(Tag.PNU, plainText) != null) { string s = ""; foreach (byte encryptedByte in encrypted) { s += encryptedByte.ToString(); } fileWriter.WriteFile(TagDecoder.GetValueByTag(Tag.PNU, plainText), s); } return(encrypted); }
private void HandleSetResistance(string packet) { int resistancePercentage = int.Parse(TagDecoder.GetValueByTag(Tag.SR, packet)); Console.WriteLine(resistancePercentage); this.BleConnect.doctorMessage = $"Resistance to {resistancePercentage}%"; this.BleConnect.SetResistance(resistancePercentage); }
private void HandlePacket(string packet) { string messageType = TagDecoder.GetValueByTag(Tag.MT, packet); if (messageType == "ergo") { this.HandleErgoMessage(packet); } }
private void HandleErgoMessage(string packet) { string action = TagDecoder.GetValueByTag(Tag.AC, packet); if (action == "resistance") { this.HandleSetResistance(packet); } else if (action == "emergencybrake") { this.HandleEmergencyBrake(packet); } else if (action == "brake") { this.HandleStopSession(packet); } else if (action == "message") { this.HandleDoctorsMessage(packet); } }
private void HandleDoctorsMessage(string packet) { string message = TagDecoder.GetValueByTag(Tag.DM, packet); this.BleConnect.doctorMessage = $"{message}"; }