@@ -98,6 +98,9 @@ private class response_structure
9898
9999 [ DataMember ]
100100 public List < users > users { get ; set ; }
101+
102+ [ DataMember ( Name = "2fa" , IsRequired = false , EmitDefaultValue = false ) ] // Ensure mapping to "2fa"
103+ public TwoFactorData twoFactor { get ; set ; } // Add a property for the 2FA data
101104 }
102105
103106 public class msg
@@ -354,7 +357,7 @@ public void forgot(string username, string email)
354357 /// </summary>
355358 /// <param name="username">Username</param>
356359 /// <param name="pass">Password</param>
357- public void login ( string username , string pass )
360+ public void login ( string username , string pass , string code = null )
358361 {
359362 CheckInit ( ) ;
360363
@@ -368,7 +371,8 @@ public void login(string username, string pass)
368371 [ "hwid" ] = hwid ,
369372 [ "sessionid" ] = sessionid ,
370373 [ "name" ] = name ,
371- [ "ownerid" ] = ownerid
374+ [ "ownerid" ] = ownerid ,
375+ [ "code" ] = code ?? string . Empty
372376 } ;
373377
374378 var response = req ( values_to_upload ) ;
@@ -599,7 +603,7 @@ public void upgrade(string username, string key)
599603 /// Authenticate without using usernames and passwords
600604 /// </summary>
601605 /// <param name="key">Licence used to login with</param>
602- public void license ( string key )
606+ public void license ( string key , string code = null )
603607 {
604608 CheckInit ( ) ;
605609
@@ -612,7 +616,8 @@ public void license(string key)
612616 [ "hwid" ] = hwid ,
613617 [ "sessionid" ] = sessionid ,
614618 [ "name" ] = name ,
615- [ "ownerid" ] = ownerid
619+ [ "ownerid" ] = ownerid ,
620+ [ "code" ] = code ?? string . Empty
616621 } ;
617622
618623 var response = req ( values_to_upload ) ;
@@ -661,6 +666,73 @@ public void check()
661666 }
662667 }
663668 /// <summary>
669+ /// Disable two factor authentication (2fa)
670+ /// </summary>
671+ public void disable2fa ( string code )
672+ {
673+ CheckInit ( ) ;
674+
675+ var values_to_upload = new NameValueCollection
676+ {
677+ [ "type" ] = "2fadisable" ,
678+ [ "sessionid" ] = sessionid ,
679+ [ "name" ] = name ,
680+ [ "ownerid" ] = ownerid ,
681+ [ "code" ] = code
682+ } ;
683+
684+ var response = req ( values_to_upload ) ;
685+
686+ var json = response_decoder . string_to_generic < response_structure > ( response ) ;
687+ load_response_struct ( json ) ;
688+
689+ Console . WriteLine ( json . message ) ;
690+ }
691+ /// <summary>
692+ /// Enable two factor authentication (2fa)
693+ /// </summary>
694+ public void enable2fa ( string code = null )
695+ {
696+ CheckInit ( ) ;
697+
698+ var values_to_upload = new NameValueCollection
699+ {
700+ [ "type" ] = "2faenable" ,
701+ [ "sessionid" ] = sessionid ,
702+ [ "name" ] = name ,
703+ [ "ownerid" ] = ownerid ,
704+ [ "code" ] = code
705+ } ;
706+
707+ var response = req ( values_to_upload ) ;
708+
709+ var json = response_decoder . string_to_generic < response_structure > ( response ) ;
710+ load_response_struct ( json ) ;
711+
712+ if ( json . success )
713+ {
714+ if ( code == null )
715+ {
716+ Console . WriteLine ( $ "Your 2FA Secret is: { json . twoFactor . SecretCode } ") ;
717+
718+ Console . Write ( "Enter the 6 digit authentication code from your authentication app: " ) ;
719+ string code6Digit = Console . ReadLine ( ) ;
720+ this . enable2fa ( code6Digit ) ;
721+ }
722+ else
723+ {
724+ Console . WriteLine ( "2FA has been successfully enabled!" ) ;
725+ Thread . Sleep ( 3000 ) ;
726+ }
727+ }
728+ else
729+ {
730+ Console . WriteLine ( $ "Error: { json . message } ") ;
731+ Thread . Sleep ( 3000 ) ;
732+ TerminateProcess ( GetCurrentProcess ( ) , 1 ) ;
733+ }
734+ }
735+ /// <summary>
664736 /// Change the data of an existing user variable, *User must be logged in*
665737 /// </summary>
666738 /// <param name="var">User variable name</param>
@@ -1173,7 +1245,7 @@ private static bool assertSSL(object sender, X509Certificate certificate, X509Ch
11731245
11741246 private static void sigCheck ( string resp , WebHeaderCollection headers , string type )
11751247 {
1176- if ( type == "log" || type == "file" ) // log doesn't return a response.
1248+ if ( type == "log" || type == "file" || type == "2faenable" || type == "2fadisable" ) // log doesn't return a response.
11771249 {
11781250 return ;
11791251 }
@@ -1282,6 +1354,16 @@ private void load_user_data(user_data_structure data)
12821354 }
12831355 #endregion
12841356
1357+ [ DataContract ]
1358+ private class TwoFactorData
1359+ {
1360+ [ DataMember ( Name = "secret_code" ) ]
1361+ public string SecretCode { get ; set ; }
1362+
1363+ [ DataMember ( Name = "QRCode" ) ]
1364+ public string QRCode { get ; set ; }
1365+ }
1366+
12851367 #region response_struct
12861368 public response_class response = new response_class ( ) ;
12871369
@@ -1295,7 +1377,7 @@ private void load_response_struct(response_structure data)
12951377 {
12961378 response . success = data . success ;
12971379 response . message = data . message ;
1298- }
1380+ }
12991381 #endregion
13001382
13011383 private json_wrapper response_decoder = new json_wrapper ( new response_structure ( ) ) ;
0 commit comments