Make most requests use id instead of username
This commit is contained in:
parent
69ccfd3421
commit
9183651c4f
3 changed files with 32 additions and 29 deletions
|
|
@ -20,7 +20,7 @@ public class Requests
|
|||
public static async Task Delete(HttpContext context, Func<Task> next, IQueryCollection query,
|
||||
StreamReader bodyReader)
|
||||
{
|
||||
if (!query.TryGetValue("u", out var username))
|
||||
if (!query.TryGetValue("id", out var idQuery))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -30,9 +30,9 @@ public class Requests
|
|||
return;
|
||||
}
|
||||
|
||||
string id = await Utils.IdFromName(username);
|
||||
string id = idQuery.ToString().Split(":")[0];
|
||||
string password = await Utils.GetPassword(id);
|
||||
secret = await Utils.NonceDecryptBody(username, password, secret);
|
||||
secret = await Utils.NonceDecryptBody(id, password, secret);
|
||||
string auth = await Utils.Auth(id, password, secret);
|
||||
if (auth != Utils.LOGIN_SUCCESS)
|
||||
{
|
||||
|
|
@ -279,7 +279,7 @@ public class Requests
|
|||
|
||||
public static async Task Auth(HttpContext context, Func<Task> next, IQueryCollection query, StreamReader bodyReader)
|
||||
{
|
||||
if (!query.TryGetValue("u", out var username))
|
||||
if (!query.TryGetValue("id", out var idQuery))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -289,9 +289,9 @@ public class Requests
|
|||
return;
|
||||
}
|
||||
|
||||
string id = await Utils.IdFromName(username);
|
||||
string id = idQuery.ToString().Split(":")[0];
|
||||
string password = await Utils.GetPassword(id);
|
||||
secret = await Utils.NonceDecryptBody(username, password, secret);
|
||||
secret = await Utils.NonceDecryptBody(id, password, secret);
|
||||
string auth = await Utils.Auth(id, password, secret);
|
||||
|
||||
await context.Response.WriteAsync(auth);
|
||||
|
|
@ -359,19 +359,20 @@ public class Requests
|
|||
|
||||
public static async Task NextNonce(HttpContext context, Func<Task> next, IQueryCollection query)
|
||||
{
|
||||
if (!query.TryGetValue("u", out var username))
|
||||
if (!query.TryGetValue("id", out var idQuery))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string plainPass = await Utils.GetPassword(await Utils.IdFromName(username));
|
||||
string id = idQuery.ToString().Split(":")[0];
|
||||
string plainPass = await Utils.GetPassword(id);
|
||||
foreach (var kvp in nonceHolder) //clearowanie nieuzytych nonce
|
||||
{
|
||||
if (kvp.Value.Item2 < DateTimeOffset.UtcNow.AddMinutes(-2))
|
||||
{
|
||||
nonceHolder.TryRemove(kvp.Key, out _);
|
||||
}
|
||||
else if (kvp.Key == username)
|
||||
else if (kvp.Key == id)
|
||||
{
|
||||
await context.Response.WriteAsync(Encryption.Encryption.EncryptString(kvp.Value.Item1,
|
||||
plainPass));
|
||||
|
|
@ -380,7 +381,7 @@ public class Requests
|
|||
}
|
||||
|
||||
string nonce = Encryption.Encryption.GetRandomString(64);
|
||||
nonceHolder.TryAdd(username, (nonce, DateTimeOffset.UtcNow));
|
||||
nonceHolder.TryAdd(id, (nonce, DateTimeOffset.UtcNow));
|
||||
await context.Response.WriteAsync(Encryption.Encryption.EncryptString(nonce,
|
||||
plainPass));
|
||||
return;
|
||||
|
|
@ -389,7 +390,7 @@ public class Requests
|
|||
public static async Task ChangePassword(HttpContext context, Func<Task> next, IQueryCollection query,
|
||||
StreamReader bodyReader)
|
||||
{
|
||||
if (!query.TryGetValue("u", out var username))
|
||||
if (!query.TryGetValue("id", out var idQuery))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -399,11 +400,11 @@ public class Requests
|
|||
return;
|
||||
}
|
||||
|
||||
string id = await Utils.IdFromName(username);
|
||||
string id = idQuery.ToString().Split(":")[0];
|
||||
string body = await LoadBody(bodyReader);
|
||||
string password = await Utils.GetPassword(id);
|
||||
string newPass = await Utils.NonceDecryptBody(username, password, body, false);
|
||||
secret = await Utils.NonceDecryptBody(username, password, secret);
|
||||
string newPass = await Utils.NonceDecryptBody(id, password, body, false);
|
||||
secret = await Utils.NonceDecryptBody(id, password, secret);
|
||||
|
||||
string auth = await Utils.Auth(id, password, secret);
|
||||
|
||||
|
|
@ -437,7 +438,7 @@ public class Requests
|
|||
public static async Task ChangeUsername(HttpContext context, Func<Task> next, IQueryCollection query,
|
||||
StreamReader bodyReader)
|
||||
{
|
||||
if (!query.TryGetValue("u", out var username))
|
||||
if (!query.TryGetValue("id", out var idQuery))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -447,13 +448,13 @@ public class Requests
|
|||
return;
|
||||
}
|
||||
|
||||
string id = await Utils.IdFromName(username);
|
||||
string id = idQuery.ToString().Split(":")[0];
|
||||
string body = await LoadBody(bodyReader);
|
||||
string password = await Utils.GetPassword(id);
|
||||
|
||||
|
||||
body = await Utils.NonceDecryptBody(username, password, body, false);
|
||||
secret = await Utils.NonceDecryptBody(username, password, secret);
|
||||
body = await Utils.NonceDecryptBody(id, password, body, false);
|
||||
secret = await Utils.NonceDecryptBody(id, password, secret);
|
||||
|
||||
string auth = await Utils.Auth(id, secret, password);
|
||||
if (auth != Utils.LOGIN_SUCCESS)
|
||||
|
|
@ -538,7 +539,7 @@ public class Requests
|
|||
|
||||
public static async Task EncryptedRequest(HttpContext context, Func<Task> next, IQueryCollection query, StreamReader bodyReader)
|
||||
{
|
||||
if (!query.TryGetValue("u", out var username))
|
||||
if (!query.TryGetValue("id", out var idQuery))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -548,11 +549,11 @@ public class Requests
|
|||
return;
|
||||
}
|
||||
|
||||
string id = await Utils.IdFromName(username);
|
||||
string id = idQuery.ToString().Split(":")[0];
|
||||
string body = await LoadBody(bodyReader);
|
||||
string password = await Utils.GetPassword(id);
|
||||
body = await Utils.NonceDecryptBody(username, password, body, false);
|
||||
secret = await Utils.NonceDecryptBody(username, password, secret);
|
||||
body = await Utils.NonceDecryptBody(id, password, body, false);
|
||||
secret = await Utils.NonceDecryptBody(id, password, secret);
|
||||
|
||||
Universal2String serializedBody = JsonSerializer.Deserialize(
|
||||
body,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue