formated all files
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System.Security.Cryptography;
|
||||
using Newtonsoft.Json;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Server
|
||||
@@ -15,7 +13,9 @@ namespace Server
|
||||
byte[] salt = new byte[16];
|
||||
RandomNumberGenerator.Fill(salt);
|
||||
// Create a PBKDF2 instance to hash the password
|
||||
using (var pbkdf2 = new Rfc2898DeriveBytes(password, salt, 10000, HashAlgorithmName.SHA256))
|
||||
using (
|
||||
var pbkdf2 = new Rfc2898DeriveBytes(password, salt, 10000, HashAlgorithmName.SHA256)
|
||||
)
|
||||
{
|
||||
byte[] hash = pbkdf2.GetBytes(32);
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Server
|
||||
return Convert.ToBase64String(hashBytes);
|
||||
}
|
||||
}
|
||||
|
||||
public static void HandleRequest(HttpListenerRequest request, HttpListenerResponse response)
|
||||
{
|
||||
MySqlTransaction? transaction = null;
|
||||
@@ -35,7 +36,12 @@ namespace Server
|
||||
{
|
||||
// extract parameters from req body
|
||||
string body;
|
||||
using (StreamReader bodyReader = new StreamReader(request.InputStream, request.ContentEncoding))
|
||||
using (
|
||||
StreamReader bodyReader = new StreamReader(
|
||||
request.InputStream,
|
||||
request.ContentEncoding
|
||||
)
|
||||
)
|
||||
{
|
||||
body = bodyReader.ReadToEnd();
|
||||
}
|
||||
@@ -46,10 +52,20 @@ namespace Server
|
||||
string mail = jsonObject["mail"]?.ToString() ?? "";
|
||||
|
||||
// validate parameters
|
||||
if (string.IsNullOrEmpty(f_name) || f_name.Length > 30 || f_name.Length < 2 ||
|
||||
string.IsNullOrEmpty(l_name) || l_name.Length > 30 || l_name.Length < 2 ||
|
||||
string.IsNullOrEmpty(mail) || mail.Length > 50 || mail.Length < 6 ||
|
||||
string.IsNullOrEmpty(password) || password.Length > 30 || password.Length < 10)
|
||||
if (
|
||||
string.IsNullOrEmpty(f_name)
|
||||
|| f_name.Length > 30
|
||||
|| f_name.Length < 2
|
||||
|| string.IsNullOrEmpty(l_name)
|
||||
|| l_name.Length > 30
|
||||
|| l_name.Length < 2
|
||||
|| string.IsNullOrEmpty(mail)
|
||||
|| mail.Length > 50
|
||||
|| mail.Length < 6
|
||||
|| string.IsNullOrEmpty(password)
|
||||
|| password.Length > 30
|
||||
|| password.Length < 10
|
||||
)
|
||||
{
|
||||
throw new Exception("Wrong parameters");
|
||||
}
|
||||
@@ -58,7 +74,8 @@ namespace Server
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
|
||||
// Insert into User
|
||||
cmd.CommandText = "INSERT INTO User(f_name,l_name,mail) VALUES(@f_name,@l_name,@mail)";
|
||||
cmd.CommandText =
|
||||
"INSERT INTO User(f_name,l_name,mail) VALUES(@f_name,@l_name,@mail)";
|
||||
cmd.Parameters.AddWithValue("@f_name", f_name);
|
||||
cmd.Parameters.AddWithValue("@l_name", l_name);
|
||||
cmd.Parameters.AddWithValue("@mail", mail);
|
||||
|
||||
Reference in New Issue
Block a user