merge conflicts 7: conflictnado

This commit is contained in:
Sem van der Hoeven
2020-10-02 11:49:48 +02:00
9 changed files with 138 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ using System.Net.Sockets;
using System.Text;
using Client;
using Newtonsoft.Json;
using System.Security.Cryptography;
namespace Server
{
@@ -19,6 +20,7 @@ namespace Server
private SaveData saveData;
private string username = null;
private DateTime sessionStart;
private const string fileName = "userInfo.dat";
@@ -132,6 +134,10 @@ namespace Server
break;
}
saveData?.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
Array.Copy(message, 5, payloadbytes, 0, message.Length - 5);
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
}
else if (DataParser.isRawData(message))
{
@@ -160,9 +166,58 @@ namespace Server
private bool verifyLogin(string username, string password)
{
return username == password;
Console.WriteLine("got hashes " + username + "\n" + password);
if (!File.Exists(fileName))
{
File.Create(fileName);
Console.WriteLine("file doesnt exist");
newUsers(username, password);
Console.WriteLine("true");
return true;
} else
{
Console.WriteLine("file exists, located at " + Path.GetFullPath(fileName));
string[] usernamesPasswords = File.ReadAllLines(fileName);
if (usernamesPasswords.Length == 0)
{
newUsers(username, password);
return true;
}
foreach (string s in usernamesPasswords)
{
string[] combo = s.Split(" ");
if (combo[0] == username)
{
Console.WriteLine("correct info");
return combo[1] == password;
}
}
Console.WriteLine("combo was not found in file");
}
Console.WriteLine("false");
return false;
}
private void newUsers(string username, string password)
{
Console.WriteLine("creating new entry in file");
using (StreamWriter sw = File.AppendText(fileName))
{
sw.WriteLine(username + " " + password);
}
}
public static string ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);