progress on validation
This commit is contained in:
@@ -158,7 +158,11 @@ namespace Client
|
|||||||
Console.WriteLine("enter password");
|
Console.WriteLine("enter password");
|
||||||
string password = Console.ReadLine();
|
string password = Console.ReadLine();
|
||||||
|
|
||||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, password));
|
string hashUser = Hashing.Hasher.Encrypt(username);
|
||||||
|
string hashPassword = Hashing.Hasher.Encrypt(password);
|
||||||
|
Console.WriteLine("hashed to " + hashUser + " " + hashPassword);
|
||||||
|
|
||||||
|
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword));
|
||||||
|
|
||||||
initEngine();
|
initEngine();
|
||||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
|
|||||||
@@ -15,4 +15,6 @@
|
|||||||
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
|
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
using Hardware;
|
using Hardware;
|
||||||
using Hardware.Simulators;
|
using Hardware.Simulators;
|
||||||
using RH_Engine;
|
using RH_Engine;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
@@ -12,7 +14,6 @@ namespace Client
|
|||||||
Console.WriteLine("Hello World!");
|
Console.WriteLine("Hello World!");
|
||||||
//connect fiets?
|
//connect fiets?
|
||||||
|
|
||||||
|
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
51
Hashing/Hasher.cs
Normal file
51
Hashing/Hasher.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Hashing
|
||||||
|
{
|
||||||
|
class Hasher
|
||||||
|
{
|
||||||
|
static string key = "ProftaakRH-B4";
|
||||||
|
public static string Encrypt(string text)
|
||||||
|
{
|
||||||
|
using (var md5 = new MD5CryptoServiceProvider())
|
||||||
|
{
|
||||||
|
using (var tdes = new TripleDESCryptoServiceProvider())
|
||||||
|
{
|
||||||
|
tdes.Key = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
|
||||||
|
tdes.Mode = CipherMode.ECB;
|
||||||
|
tdes.Padding = PaddingMode.PKCS7;
|
||||||
|
|
||||||
|
using (var transform = tdes.CreateEncryptor())
|
||||||
|
{
|
||||||
|
byte[] textBytes = UTF8Encoding.UTF8.GetBytes(text);
|
||||||
|
byte[] bytes = transform.TransformFinalBlock(textBytes, 0, textBytes.Length);
|
||||||
|
return Convert.ToBase64String(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Decrypt(string cipher)
|
||||||
|
{
|
||||||
|
using (var md5 = new MD5CryptoServiceProvider())
|
||||||
|
{
|
||||||
|
using (var tdes = new TripleDESCryptoServiceProvider())
|
||||||
|
{
|
||||||
|
tdes.Key = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
|
||||||
|
tdes.Mode = CipherMode.ECB;
|
||||||
|
tdes.Padding = PaddingMode.PKCS7;
|
||||||
|
|
||||||
|
using (var transform = tdes.CreateDecryptor())
|
||||||
|
{
|
||||||
|
byte[] cipherBytes = Convert.FromBase64String(cipher);
|
||||||
|
byte[] bytes = transform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
|
||||||
|
return UTF8Encoding.UTF8.GetString(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Hashing/Hashing.projitems
Normal file
14
Hashing/Hashing.projitems
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||||
|
<HasSharedItems>true</HasSharedItems>
|
||||||
|
<SharedGUID>70277749-d423-4871-b692-2efc5a6ed932</SharedGUID>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Label="Configuration">
|
||||||
|
<Import_RootNamespace>Hashing</Import_RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
13
Hashing/Hashing.shproj
Normal file
13
Hashing/Hashing.shproj
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>70277749-d423-4871-b692-2efc5a6ed932</ProjectGuid>
|
||||||
|
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||||
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||||
|
<PropertyGroup />
|
||||||
|
<Import Project="Hashing.projitems" Label="Shared" />
|
||||||
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
@@ -15,7 +15,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Message", "..\Message\Messa
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Hashing", "..\Hashing\Hashing.shproj", "{70277749-D423-4871-B692-2EFC5A6ED932}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||||
|
..\Hashing\Hashing.projitems*{5759dd20-7a4f-4d8d-b986-a70a7818c112}*SharedItemsImports = 5
|
||||||
|
..\Hashing\Hashing.projitems*{70277749-d423-4871-b692-2efc5a6ed932}*SharedItemsImports = 13
|
||||||
|
..\Hashing\Hashing.projitems*{b1ab6f51-a20d-4162-9a7f-b3350b7510fd}*SharedItemsImports = 5
|
||||||
|
EndGlobalSection
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Net.Sockets;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Client;
|
using Client;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace Server
|
namespace Server
|
||||||
{
|
{
|
||||||
@@ -19,6 +20,7 @@ namespace Server
|
|||||||
private SaveData saveData;
|
private SaveData saveData;
|
||||||
private string username = null;
|
private string username = null;
|
||||||
private DateTime sessionStart;
|
private DateTime sessionStart;
|
||||||
|
private const string fileName = "userInfo.dat";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -125,6 +127,7 @@ namespace Server
|
|||||||
}
|
}
|
||||||
Array.Copy(message, 5, payloadbytes, 0, message.Length - 5);
|
Array.Copy(message, 5, payloadbytes, 0, message.Length - 5);
|
||||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
||||||
|
|
||||||
saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
|
saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -139,9 +142,48 @@ namespace Server
|
|||||||
|
|
||||||
private bool verifyLogin(string username, string password)
|
private bool verifyLogin(string username, string password)
|
||||||
{
|
{
|
||||||
return username == password;
|
Console.WriteLine("got hashes " + username + password);
|
||||||
|
Console.WriteLine(Hashing.Hasher.Decrypt(username) + " " + Hashing.Hasher.Decrypt(password));
|
||||||
|
|
||||||
|
if (!File.Exists(fileName))
|
||||||
|
{
|
||||||
|
Console.WriteLine("file doesnt exist");
|
||||||
|
|
||||||
|
Console.WriteLine("true");
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
string[] usernamesPasswords = File.ReadAllLines(fileName);
|
||||||
|
|
||||||
|
foreach (string s in usernamesPasswords)
|
||||||
|
{
|
||||||
|
string[] combo = s.Split(";");
|
||||||
|
if (combo[0] == username)
|
||||||
|
{
|
||||||
|
Console.WriteLine("true");
|
||||||
|
return combo[1] == password;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Console.WriteLine("false");
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void newUsers(string username, string password)
|
||||||
|
{
|
||||||
|
File.Create(fileName);
|
||||||
|
using (StreamWriter sw = File.AppendText(fileName))
|
||||||
|
{
|
||||||
|
sw.WriteLine(username + ";" + password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static string ByteArrayToString(byte[] ba)
|
public static string ByteArrayToString(byte[] ba)
|
||||||
{
|
{
|
||||||
StringBuilder hex = new StringBuilder(ba.Length * 2);
|
StringBuilder hex = new StringBuilder(ba.Length * 2);
|
||||||
|
|||||||
@@ -13,4 +13,6 @@
|
|||||||
<ProjectReference Include="..\Client\Client.csproj" />
|
<ProjectReference Include="..\Client\Client.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user