mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-20 19:59:15 +12:00
Add Feature pt1
This commit is contained in:
parent
a184e4d735
commit
092534e331
131 changed files with 3113 additions and 1418 deletions
88
HorseIsleServer/LibHISP/Security/Authentication.cs
Normal file
88
HorseIsleServer/LibHISP/Security/Authentication.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
using HISP.Server;
|
||||
|
||||
namespace HISP.Security
|
||||
{
|
||||
public class Authentication
|
||||
{
|
||||
public static string DecryptLogin(string encpass)
|
||||
{
|
||||
string decrypt = "";
|
||||
string ROTPOOL = "bl7Jgk61IZdnY mfDN5zjM2XLqTCty4WSEoKR3BFVQsaUhHOAx0rPwp9uc8iGve";
|
||||
string POSPOOL = "DQc3uxiGsKZatMmOS5qYveN71zoPTk8yU0H2w9VjprBXWn l4FJd6IRbhgACfEL";
|
||||
string ROTPOOL2 = "evGi8cu9pwPr0xAOHhUasQVFB3RKoESW4ytCTqLX2Mjz5NDfm YndZI16kgJ7lb";
|
||||
|
||||
|
||||
int i = 0;
|
||||
int ii = 0;
|
||||
while (i < encpass.Length)
|
||||
{
|
||||
int ROT = ROTPOOL.IndexOf(encpass[i].ToString());
|
||||
int POS = POSPOOL.IndexOf(encpass[i + 1].ToString());
|
||||
POS -= (ROT + ii);
|
||||
if (POS < 0)
|
||||
{
|
||||
POS = (POS / -1) - 1;
|
||||
|
||||
while (POS >= ROTPOOL.Length)
|
||||
{
|
||||
POS -= ROTPOOL.Length;
|
||||
}
|
||||
|
||||
decrypt += ROTPOOL2[POS];
|
||||
}
|
||||
else
|
||||
{
|
||||
while (POS >= ROTPOOL.Length)
|
||||
{
|
||||
POS -= ROTPOOL.Length;
|
||||
}
|
||||
|
||||
decrypt += ROTPOOL[POS];
|
||||
}
|
||||
|
||||
i += 2;
|
||||
ii += 1;
|
||||
}
|
||||
return decrypt.Replace(" ", "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static byte[] HashAndSalt(string plaintext, byte[] salt)
|
||||
{
|
||||
byte[] plaintextBytes = Encoding.UTF8.GetBytes(plaintext);
|
||||
|
||||
SHA512 sha512 = SHA512.Create();
|
||||
byte[] hash = sha512.ComputeHash(plaintextBytes);
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
hash[i] ^= salt[i];
|
||||
}
|
||||
|
||||
byte[] finalHash = sha512.ComputeHash(hash);
|
||||
|
||||
return finalHash;
|
||||
}
|
||||
|
||||
public static bool CheckPassword(string username, string password)
|
||||
{
|
||||
if(Database.CheckUserExist(username))
|
||||
{
|
||||
byte[] expectedPassword = Database.GetPasswordHash(username);
|
||||
byte[] salt = Database.GetPasswordSalt(username);
|
||||
byte[] hashedPassword = HashAndSalt(password, salt);
|
||||
|
||||
if (Enumerable.SequenceEqual(expectedPassword, hashedPassword))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
35
HorseIsleServer/LibHISP/Security/BBCode.cs
Normal file
35
HorseIsleServer/LibHISP/Security/BBCode.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace HISP.Security
|
||||
{
|
||||
public class BBCode
|
||||
{
|
||||
public BBCode(string tag, string meta)
|
||||
{
|
||||
this.Tag = tag;
|
||||
this.MetaTranslation = meta;
|
||||
bbcodeTranslations.Add(this);
|
||||
}
|
||||
private static List<BBCode> bbcodeTranslations = new List<BBCode>();
|
||||
public string Tag;
|
||||
public string MetaTranslation;
|
||||
|
||||
public static string EncodeMetaToBBCode(string message)
|
||||
{
|
||||
foreach (BBCode code in bbcodeTranslations)
|
||||
{
|
||||
message = message.Replace(code.MetaTranslation, code.Tag);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
public static string EncodeBBCodeToMeta(string message)
|
||||
{
|
||||
foreach(BBCode code in bbcodeTranslations)
|
||||
{
|
||||
message = message.Replace(code.Tag, code.MetaTranslation);
|
||||
message = message.Replace(code.Tag.ToUpper(), code.MetaTranslation);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
28
HorseIsleServer/LibHISP/Security/CrossDomainPolicy.cs
Normal file
28
HorseIsleServer/LibHISP/Security/CrossDomainPolicy.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using HISP.Properties;
|
||||
using System.IO;
|
||||
using HISP.Server;
|
||||
namespace HISP.Security
|
||||
{
|
||||
public class CrossDomainPolicy
|
||||
{
|
||||
public static byte[] GetPolicy()
|
||||
{
|
||||
if (!File.Exists(ConfigReader.CrossDomainPolicyFile)) {
|
||||
Logger.InfoPrint("Cross-Domain-Policy file not found, using default");
|
||||
File.WriteAllText(ConfigReader.CrossDomainPolicyFile, Resources.DefaultCrossDomain);
|
||||
}
|
||||
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] policyFileBytes = File.ReadAllBytes(ConfigReader.CrossDomainPolicyFile);
|
||||
ms.Write(policyFileBytes, 0x00, policyFileBytes.Length);
|
||||
ms.WriteByte(0x00);
|
||||
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] policyFileData = ms.ToArray();
|
||||
ms.Close();
|
||||
|
||||
return policyFileData;
|
||||
}
|
||||
}
|
||||
}
|
21
HorseIsleServer/LibHISP/Security/RandomID.cs
Normal file
21
HorseIsleServer/LibHISP/Security/RandomID.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
namespace HISP.Security
|
||||
{
|
||||
public class RandomID
|
||||
{
|
||||
private static int prevId = 0;
|
||||
public static int NextRandomId(int randomId=-1)
|
||||
{
|
||||
int rndmId = 0;
|
||||
|
||||
if (randomId == -1)
|
||||
rndmId = prevId+1;
|
||||
else
|
||||
rndmId = randomId;
|
||||
|
||||
if (rndmId >= prevId)
|
||||
prevId = rndmId;
|
||||
|
||||
return rndmId;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue