mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-06 03:48:40 +00:00
Authentication works
This commit is contained in:
parent
85da92124e
commit
b287e34425
8 changed files with 63 additions and 23 deletions
|
@ -1,8 +1,8 @@
|
|||
create table Locations
|
||||
(
|
||||
Id int not null,
|
||||
X int not null,
|
||||
Y int not null
|
||||
Id int not null,
|
||||
X int not null,
|
||||
Y int not null
|
||||
);
|
||||
|
||||
create unique index Locations_UserId_uindex
|
||||
|
@ -15,3 +15,7 @@ alter table Locations
|
|||
alter table Users
|
||||
add LocationId int null;
|
||||
|
||||
alter table Locations
|
||||
modify Id int auto_increment;
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
create table Tokens
|
||||
(
|
||||
UserId int not null,
|
||||
TokenId int,
|
||||
UserId int not null,
|
||||
UserToken text not null
|
||||
);
|
||||
|
||||
create unique index Tokens_TokenId_uindex
|
||||
on Tokens (TokenId);
|
||||
|
||||
alter table Tokens
|
||||
add constraint Tokens_pk
|
||||
primary key (TokenId);
|
||||
|
||||
alter table Tokens
|
||||
modify TokenId int auto_increment;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Braaains/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=brun/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ezoiar/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=farc/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=lbpme/@EntryIndexedValue">True</s:Boolean>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ProjectLighthouse.Helpers;
|
||||
using ProjectLighthouse.Types;
|
||||
|
||||
namespace ProjectLighthouse {
|
||||
|
@ -38,8 +39,8 @@ namespace ProjectLighthouse {
|
|||
|
||||
public async Task<Token?> AuthenticateUser(LoginData loginData) {
|
||||
// TODO: don't use psn name to authenticate
|
||||
User user = await this.Users.FirstOrDefaultAsync(u => u.Username == loginData.Username + u.Username[-1])
|
||||
?? await this.CreateUser(loginData.Username + "_");
|
||||
User user = await this.Users.FirstOrDefaultAsync(u => u.Username == loginData.Username)
|
||||
?? await this.CreateUser(loginData.Username);
|
||||
|
||||
Token token = new() {
|
||||
UserToken = HashHelper.GenerateAuthToken(),
|
||||
|
|
26
ProjectLighthouse/Helpers/BinaryHelper.cs
Normal file
26
ProjectLighthouse/Helpers/BinaryHelper.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectLighthouse.Helpers {
|
||||
public static class BinaryHelper {
|
||||
public static string ReadString(BinaryReader reader) {
|
||||
List<byte> readBytes = new();
|
||||
|
||||
byte readByte;
|
||||
do {
|
||||
readBytes.Add(readByte = reader.ReadByte());
|
||||
} while(readByte != 0x00);
|
||||
|
||||
return Encoding.UTF8.GetString(readBytes.ToArray());
|
||||
}
|
||||
|
||||
public static void ReadUntilByte(BinaryReader reader, byte byteToReadTo) {
|
||||
byte readByte;
|
||||
do {
|
||||
readByte = reader.ReadByte();
|
||||
} while(readByte != byteToReadTo);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectLighthouse {
|
||||
namespace ProjectLighthouse.Helpers {
|
||||
public static class HashHelper {
|
||||
// private static readonly SHA1 sha1 = SHA1.Create();
|
||||
private static readonly SHA256 sha256 = SHA256.Create();
|
|
@ -1,5 +1,6 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using ProjectLighthouse.Helpers;
|
||||
|
||||
namespace ProjectLighthouse.Types {
|
||||
// This is all the information I can understand for now. More testing is required.
|
||||
|
@ -14,28 +15,26 @@ namespace ProjectLighthouse.Types {
|
|||
/// The data sent from POST /LOGIN.
|
||||
/// </summary>
|
||||
public class LoginData {
|
||||
public string Username { get; set; } // Cut off by one for some strange reason
|
||||
public string GameVersion { get; set; }
|
||||
public int UnknownNumber { get; set; } // Seems to increment by 1000 every login attempt
|
||||
public string Username { get; set; }
|
||||
// public string GameVersion { get; set; }
|
||||
// public int UnknownNumber { get; set; } // Seems to increment by 1000 every login attempt
|
||||
|
||||
public static LoginData CreateFromString(string str) {
|
||||
do {
|
||||
str = str.Replace("\b", "");
|
||||
} while(str.Contains('\b'));
|
||||
|
||||
using MemoryStream ms = new(Encoding.ASCII.GetBytes(str));
|
||||
using BinaryReader reader = new(ms);
|
||||
|
||||
LoginData loginData = new();
|
||||
|
||||
reader.ReadBytes(4); // Perhaps a header of sorts?
|
||||
|
||||
string number = Encoding.ASCII.GetString(reader.ReadBytes(7)); // Number is stored as text for some reason...
|
||||
loginData.UnknownNumber = int.Parse(number);
|
||||
BinaryHelper.ReadUntilByte(reader, 0x20); // Skips to relevant part
|
||||
|
||||
reader.ReadBytes(10); // No clue what this is.
|
||||
|
||||
string end = Encoding.ASCII.GetString(reader.ReadBytes(int.MaxValue)); // ReadToEnd 2: Electric Boogaloo
|
||||
string[] split = end.Split("bru"); // No idea what it means, but it seems to split the gameversion and username apart
|
||||
// byte[] endBytes = reader.ReadBytes((int)(ms.Length - reader.BaseStream.Position));
|
||||
// string end = Encoding.ASCII.GetString(endBytes);
|
||||
|
||||
loginData.Username = split[0];
|
||||
loginData.GameVersion = split[1];
|
||||
loginData.Username = BinaryHelper.ReadString(reader);
|
||||
|
||||
return loginData;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ProjectLighthouse.Types {
|
||||
[Keyless]
|
||||
public class Token {
|
||||
public int TokenId { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public string UserToken { get; set; }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue