Esempio n. 1
0
 public bool?AuthenticateUser(String userName, String password)
 {
     if (!this.usersCredentials.ContainsKey(userName))
     {
         return(null);
     }
     return(Sec.hash_and_compare(password, usersCredentials[userName]));
 }
Esempio n. 2
0
 public bool AddUser(String userName, String password)
 {
     if (this.usersCredentials.ContainsKey(userName))
     {
         return(false);
     }
     usersCredentials[userName] = Sec.hash(password);
     return(true);
 }
Esempio n. 3
0
        public void StoreData()
        {
            string s = JsonConvert.SerializeObject(this.Data, Formatting.None, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            }).Trim();

            s = Sec.encrypt(s, DataSupervisor.ds.userPasswrd);
            File.WriteAllText(this.WorkingFile, s);
        }
Esempio n. 4
0
        public void StoreData()
        {
            string saveData = JsonConvert.SerializeObject(this.Data, Formatting.Indented, new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto,
            });
            string encrypted = Sec.encrypt(saveData, DataSupervisor.ds.userPasswrd);

            File.WriteAllText(this.WorkingFile, encrypted);
        }
Esempio n. 5
0
        public void SaveUserProfile()
        {
            String userDirectory = Environment.CurrentDirectory + $"\\Data\\{this.user.userName}";

            if (!Directory.Exists(userDirectory))
            {
                Directory.CreateDirectory(userDirectory);
            }
            String rawJSON       = JsonConvert.SerializeObject(this.user);
            String encryptedJSON = Sec.encrypt(rawJSON, DataSupervisor.ds.userPasswrd);

            File.WriteAllText(userDirectory + "\\userProfile.json", encryptedJSON);
        }
Esempio n. 6
0
 private static String IP = "127.0.0.1"; //"192.168.43.162"; // IP ADDRESS OR DOMAIN NAME
 private static bool alive()
 {
     try
     {
         byte[] data = Encoding.ASCII.GetBytes(Sec.encrypt("PING", Sec.dh_secret));
         stream.Write(data, 0, data.Length);
         w.Flush();
         if (Sec.decrypt(r.ReadLine(), Sec.dh_secret) == "PONG")
         {
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 7
0
        // Loads the user profile data from its corresponding file
        private void LoadUserProfile(String username)
        {
            string dataPath = this.currentUserDataPath + @"\userProfile.json";

            if (this.user != null)
            {
                return;
            }
            if (File.Exists(dataPath))
            {
                String rawJSON       = "{}";
                String decryptedJSON = "{}";
                rawJSON = File.ReadAllText(dataPath).Trim();
                if (rawJSON == "")
                {
                    decryptedJSON = "{}";
                }
                else
                {
                    decryptedJSON = Sec.decrypt(rawJSON, DataSupervisor.ds.userPasswrd);
                }
                this.user = JsonConvert.DeserializeObject <User>(decryptedJSON);
            }
        }
Esempio n. 8
0
 private static void main()
 {
     while (true)
     {
         try
         {
             c = new TcpClient(IP, 1337);
             Thread.Sleep(2000);
             setConnected(c.Connected);
             setStream(c.GetStream());
             setReader(new StreamReader(stream));
             setWriter(new StreamWriter(stream));
             Sec.dh(stream, r, w); // diffie hellman
             while (true)
             {
                 if (!alive() || disconnect_requested)
                 {
                     disconnect_requested = false;
                     throw new SocketException();
                 }
                 if (IsPendingData())
                 {
                     String enc = Sec.encrypt(getPendingData(), Sec.dh_secret);
                     //MessageBox.Show(enc);
                     byte[] data = Encoding.ASCII.GetBytes(enc);
                     stream.Write(data, 0, data.Length);
                     w.Flush();
                     if (Sec.decrypt(r.ReadLine(), Sec.dh_secret) == "ACK")
                     {
                         // MessageBox.Show("ACK"); message recu :D
                         clearPendingData();
                     }
                     else
                     {
                         // MessageBox.Show("NAK"); message non recu, reessayer l'envoi
                     }
                 }
                 Thread.Sleep(2000);
             }
         }
         catch (SocketException)
         {
             connected = false;
             if (r != null)
             {
                 r.Dispose();
             }
             if (w != null)
             {
                 w.Dispose();
             }
             if (stream != null)
             {
                 stream.Dispose();
             }
             if (c != null)
             {
                 c.Dispose();
             }
             //MessageBox.Show("disconnected : " + e.Message);
         }
     }
 }
Esempio n. 9
0
 public void ChangePassword(String username, String password)
 {
     this.usersCredentials[username] = Sec.hash(password);
 }