1- using Newtonsoft . Json ;
1+ using Newtonsoft . Json ;
22using Newtonsoft . Json . Linq ;
33using System ;
44using System . Diagnostics ;
77using System . Text ;
88using System . Windows . Forms ;
99
10- namespace Qvoid_Authentication
10+ namespace Qvoid . Authentication
1111{
1212 public abstract class FireClient
1313 {
@@ -20,7 +20,7 @@ public FireClient(string baseAddress = "", string Token = "")
2020 if ( String . IsNullOrEmpty ( baseAddress ) )
2121 throw new Exception ( "The base address was null." ) ;
2222
23- //Yes, it can be done with WebClient but I prefer HttpWebRequet.
23+ //Can be done with WebClient but I prefer HttpWebRequet.
2424 HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( $ "{ baseAddress } ?{ ( String . IsNullOrEmpty ( this . AuthSecret ) ? "" : $ "auth={ this . AuthSecret } ") } ") ;
2525 request . Method = "GET" ;
2626 try
@@ -110,16 +110,23 @@ public class LicenseKey
110110
111111 public class AuthSystem : FireClient
112112 {
113+ /// <summary>
114+ /// The webhooks structure
115+ /// </summary>
113116 internal static class Webhooks
114117 {
115- public static Discord . Webhook Login = null ;
116- public static Discord . Webhook Register = null ;
118+ public static Discord . Webhook Login = null ;
119+ public static Discord . Webhook Register = null ;
117120 public static Discord . Webhook Unauthorized = null ;
118- public static Discord . Webhook License = null ;
121+ public static Discord . Webhook License = null ;
119122 }
120123
121124 public Database . UserData LoggedUser { get ; internal set ; }
122125
126+ /// <summary>
127+ /// Connecting into the database and checks for: new update, killswitch and the webhooks.
128+ /// </summary>
129+ /// <param name="Credentials"></param>
123130 public AuthSystem ( Credentials Credentials ) : base ( Credentials . BaseAddress , Credentials . Token )
124131 {
125132 //Checking if the client has connected.
@@ -133,7 +140,7 @@ public AuthSystem(Credentials Credentials) : base(Credentials.BaseAddress, Crede
133140 if ( new Version ( $ "{ Settings [ "Version" ] } ") . CompareTo ( Credentials . Version ) > 0 )
134141 {
135142 //Update is required.
136- var result = MessageBox . Show ( $ "This distribution of the software is outdated; Would you like to install the new version?", "" , MessageBoxButtons . YesNo , MessageBoxIcon . Information ) ;
143+ var result = MessageBox . Show ( $ "This distribution of the software is outdated; Would you like to install the new version?", "Qvoid Authentication " , MessageBoxButtons . YesNo , MessageBoxIcon . Information ) ;
137144 if ( result == DialogResult . Yes )
138145 {
139146 string tempPath = Path . GetTempPath ( ) + "\\ Updater.exe" ;
@@ -152,6 +159,13 @@ public AuthSystem(Credentials Credentials) : base(Credentials.BaseAddress, Crede
152159 this . UpdateWebhooks ( $ "{ Settings [ "Webhooks" ] [ "Login" ] } ", $ "{ Settings [ "Webhooks" ] [ "Register" ] } ", $ "{ Settings [ "Webhooks" ] [ "Unautorized" ] } ", $ "{ Settings [ "Webhooks" ] [ "License" ] } ") ;
153160 }
154161
162+ /// <summary>
163+ /// Updating all the webhooks (used to synchronize the webhooks with the database)
164+ /// </summary>
165+ /// <param name="Login"></param>
166+ /// <param name="Register"></param>
167+ /// <param name="Warns"></param>
168+ /// <param name="License"></param>
155169 private void UpdateWebhooks ( string Login , string Register , string Warns , string License )
156170 {
157171 Webhooks . Login = new Discord . Webhook ( Login ) ;
@@ -161,6 +175,9 @@ private void UpdateWebhooks(string Login, string Register, string Warns, string
161175 Webhooks . Login = new Discord . Webhook ( Login ) ;
162176 }
163177
178+ /// <summary>
179+ /// Creating the database structure for the first time and registering a user which is random
180+ /// </summary>
164181 public void InitializeDatabase ( )
165182 {
166183 DateTime regTime = DateTime . UtcNow ;
@@ -170,19 +187,21 @@ public void InitializeDatabase()
170187 DateTime licenseTime = DateTime . MinValue ;
171188 licenseTime = licenseTime . AddDays ( 0 ) . AddMonths ( 0 ) . AddYears ( 3000 ) ;
172189
190+ //Creating license for our system user.
173191 Database . LicenseKey license = new Database . LicenseKey ( ) { Claimer = "System" , LicenseTime = licenseTime } ;
174192 if ( ! SetData < Database . LicenseKey > ( $ "License Keys/databaseInitKey", license ) )
175193 {
176194 MessageBox . Show ( "Internal database error." , "Databse error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
177195 return ;
178196 }
179197
198+ //Formatting the random HWID to the regular format we use.
180199 string HWID = Encryption . MD5 ( Encryption . ComputeSha256Hash ( Encryption . GenerateKey ( ) ) ) ;
181200 Database . UserData User = new Database . UserData
182201 {
183202 Admin = true ,
184203 Username = Username ,
185- Password = Encryption . StrXOR ( Password , Encryption . ROT ( Username , 13 ) , true ) ,
204+ Password = Encryption . ComputeSha256Hash ( Password ) ,
186205 DesktopName = "Administrator" ,
187206 HWID = HWID ,
188207 LastLogin = regTime ,
@@ -207,23 +226,31 @@ public void InitializeDatabase()
207226 SetData ( $ "Registered HWIDs/{ HWID } ", User . Username ) ;
208227 }
209228
210- public void FormatDatabase ( )
211- {
212- DeleteData ( "" ) ;
213- }
229+ /// <summary>
230+ /// Formmating the database.
231+ /// </summary>
232+ public void FormatDatabase ( ) => DeleteData ( "" ) ;
214233
215234 #region Blacklist
235+ /// <summary>
236+ /// Checks if the given HWID is blacklisted in the database.
237+ /// </summary>
238+ /// <param name="HWID"></param>
239+ /// <returns>User blacklist state</returns>
216240 public bool IsBlacklisted ( string HWID )
217241 {
218242 string [ ] hwids = GetData < string > ( "Blacklist" ) . Split ( ',' ) ;
219243 foreach ( string hwid in hwids )
220- {
221244 if ( hwid == HWID )
222245 return true ;
223- }
246+
224247 return false ;
225248 }
226249
250+ /// <summary>
251+ /// Adds HWID to the blacklist.
252+ /// </summary>
253+ /// <param name="HWID"></param>
227254 public void AddBlacklist ( string HWID )
228255 {
229256 if ( IsBlacklisted ( HWID ) )
@@ -236,6 +263,10 @@ public void AddBlacklist(string HWID)
236263 SetData ( "Blacklist" , hwids + "," + HWID ) ;
237264 }
238265
266+ /// <summary>
267+ /// Removes HWID from the blacklist.
268+ /// </summary>
269+ /// <param name="HWID"></param>
239270 public void RemoveBlacklist ( string HWID )
240271 {
241272 if ( ! IsBlacklisted ( HWID ) )
@@ -326,7 +357,7 @@ public Database.LicenseKey CreateLicense(string Code, int Days, int Months, int
326357 public Database . UserData Login ( string username , string password )
327358 {
328359 Database . UserData userData = GetData < Database . UserData > ( $ "User Data/{ username } ") ;
329- if ( userData == null || userData . Password != Encryption . StrXOR ( password , Encryption . ROT ( username , 13 ) , true ) )
360+ if ( userData == null || userData . Password != Encryption . ComputeSha256Hash ( password ) )
330361 {
331362 MessageBox . Show ( "Username or password is incorrect." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
332363 return null ;
@@ -361,7 +392,7 @@ public Database.UserData Login(string username, string password)
361392
362393 if ( IsBlacklisted ( Security . GetMachineIdentifier ( ) ) )
363394 {
364- //Blacklisted HWID
395+ Environment . Exit ( 0 ) ;
365396 return null ;
366397 }
367398
@@ -441,10 +472,10 @@ public Database.UserData Register(string username, string password, string licen
441472
442473 Webhooks . Register . Send ( embed ) ;
443474
444- MessageBox . Show ( "We successfully Registered your new account!\r \n Have fun using our Tool (: " , "Success!" , MessageBoxButtons . OK , MessageBoxIcon . None ) ;
475+ MessageBox . Show ( "We successfully registered your new account!" , "Success!" , MessageBoxButtons . OK , MessageBoxIcon . None ) ;
445476 return User ;
446477 }
447478 }
448479 #endregion
449480 }
450- }
481+ }
0 commit comments