From f68bb1864b40c69d12b44db5aa33125aef39e150 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 17 Mar 2018 15:33:00 +0100 Subject: Restructuring --- .../Models/ClientConnection.cs | 37 +++++++++++++++++++++ .../Models/UserInfo.cs | 38 ++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 DistributedPasswordCracker.Server/Models/ClientConnection.cs create mode 100644 DistributedPasswordCracker.Server/Models/UserInfo.cs (limited to 'DistributedPasswordCracker.Server/Models') diff --git a/DistributedPasswordCracker.Server/Models/ClientConnection.cs b/DistributedPasswordCracker.Server/Models/ClientConnection.cs new file mode 100644 index 0000000..4dab2b1 --- /dev/null +++ b/DistributedPasswordCracker.Server/Models/ClientConnection.cs @@ -0,0 +1,37 @@ +using System.IO; +using System.Net.Sockets; +using System.Threading.Tasks; + +namespace DistributedPasswordCracker.Server.Models +{ + class ClientConnection + { + public TcpClient ConnectionSocket { get; set; } + public string Chunk { get; set; } + public string Pass { get; set; } + + + public ClientConnection(TcpClient connectionSocket, string chunk, string pass) + { + ConnectionSocket = connectionSocket; + Chunk = chunk; + Pass = pass; + } + + public async Task SendToClient() + { + Stream ns = ConnectionSocket.GetStream(); + StreamReader sr = new StreamReader(ns); + StreamWriter sw = new StreamWriter(ns) + { + AutoFlush = true + }; + + sw.WriteLine($"DPCP 1.0\n{Pass}\n{Chunk}\n\n"); + //sw.WriteLine(pass); + //sw.WriteLine(chunk); + + return sr.ReadLine(); + } + } +} \ No newline at end of file diff --git a/DistributedPasswordCracker.Server/Models/UserInfo.cs b/DistributedPasswordCracker.Server/Models/UserInfo.cs new file mode 100644 index 0000000..b4df9e2 --- /dev/null +++ b/DistributedPasswordCracker.Server/Models/UserInfo.cs @@ -0,0 +1,38 @@ +using System; + +namespace DistributedPasswordCracker.Server.Models +{ + /// + /// username + encrypted password. + /// In the password file we store username + encrypted password. + /// The encrypted password is a byte array (cannot be written to the password file) + /// This must be Base64 encoded (converted to a string) before written to the file + /// + [Serializable] + class UserInfo + { + public String Username { get; set; } + public String EntryptedPasswordBase64 { get; set; } + public byte[] EntryptedPassword { get; set; } + + public UserInfo(String username, String entryptedPasswordBase64) + { + if (username == null) + { + throw new ArgumentNullException("username"); + } + if (entryptedPasswordBase64 == null) + { + throw new ArgumentNullException("entryptedPasswordBase64"); + } + Username = username; + EntryptedPasswordBase64 = entryptedPasswordBase64; + EntryptedPassword = Convert.FromBase64String(entryptedPasswordBase64); + } + + public override string ToString() + { + return Username + ":" + EntryptedPasswordBase64; + } + } +} \ No newline at end of file -- cgit v1.2.3