Skip to content

Commit

Permalink
attempt to fix 2fa login, but not working yet
Browse files Browse the repository at this point in the history
  • Loading branch information
n1d3v committed Dec 5, 2024
1 parent 6368fc7 commit 552a454
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 173 deletions.
2 changes: 0 additions & 2 deletions Naticord/Forms/Login.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 32 additions & 44 deletions Naticord/Forms/Login.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows.Forms;
Expand All @@ -22,7 +23,6 @@ public Login()
{
key.SetValue("Naticord.exe", 11001, RegistryValueKind.DWord);
}

}

protected override void OnLoad(EventArgs e)
Expand Down Expand Up @@ -68,16 +68,21 @@ private void PerformLoginWithPass(string email, string password)

var loginPayload = new
{
email = email,
password = password
gift_code_sku_id = (string)null,
login = email,
login_source = (string)null,
password = password,
undelete = false
};

Debug.WriteLine("Login Payload: " + Newtonsoft.Json.JsonConvert.SerializeObject(loginPayload));
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0";

string response = webClient.UploadString("https://discord.com/api/v9/auth/login", Newtonsoft.Json.JsonConvert.SerializeObject(loginPayload));
var json = JObject.Parse(response);

Debug.WriteLine("Login Response: " + response);

if (json["token"] != null)
{
string accessToken = json["token"].ToString();
Expand Down Expand Up @@ -116,7 +121,9 @@ public void PerformLogin(string accessToken, bool isAutomated)

try
{
Debug.WriteLine("Requesting user profile with token: " + accessToken);
string userProfileJson = webClient.DownloadString("https://discord.com/api/v9/users/@me");
Debug.WriteLine("User Profile Response: " + userProfileJson);

if (!isAutomated) SaveToken(accessToken);

Expand Down Expand Up @@ -144,16 +151,18 @@ private void Perform2FALogin(string ticket, string code)
var mfaPayload = new
{
code = code,
ticket = ticket,
gift_code_sku_id = (string)null,
login_source = (string)null,
gift_code_sku_id = (string)null
ticket = ticket
};

Debug.WriteLine("2FA Payload: " + Newtonsoft.Json.JsonConvert.SerializeObject(mfaPayload));
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0";

string response = webClient.UploadString("https://discord.com/api/v9/auth/mfa/totp", Newtonsoft.Json.JsonConvert.SerializeObject(mfaPayload));
var json = JObject.Parse(response);
string jsonResponse = webClient.UploadString("https://discord.com/api/v9/auth/mfa/totp", Newtonsoft.Json.JsonConvert.SerializeObject(mfaPayload));
var json = JObject.Parse(jsonResponse);

Debug.WriteLine("2FA Response: " + jsonResponse);

if (json["token"] != null)
{
Expand All @@ -162,12 +171,25 @@ private void Perform2FALogin(string ticket, string code)
}
else
{
Debug.WriteLine("2FA failed. Response: " + json["message"]?.ToString());
Debug.WriteLine("Full Response JSON: " + jsonResponse);

MessageBox.Show("2FA failed. Please check your 2FA code.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (WebException ex)
{
if (ex.Response != null)
{
using (var reader = new StreamReader(ex.Response.GetResponseStream()))
{
string responseBody = reader.ReadToEnd();
Debug.WriteLine("WebException Response Body: " + responseBody);
}
}

Debug.WriteLine("2FA failed. Exception Message: " + ex.Message);
MessageBox.Show("2FA failed. Please check your 2FA code! Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Expand Down Expand Up @@ -263,41 +285,7 @@ private void githubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs

private void discordStatusLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://discordstatus.com");
}

private void proxyLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{

using (var form = new Form())
using (var label = new Label() { Text = "Enter Proxy Address:" })
using (var inputBox = new TextBox())
using (var buttonOk = new Button() { Text = "OK", DialogResult = DialogResult.OK })
{
inputBox.Text = proxyAddress;

ConfigureFormControls(form, label, inputBox, buttonOk);
form.Text = "Proxy";
form.FormBorderStyle = FormBorderStyle.Sizable;

if (form.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.proxy = inputBox.Text.Trim();
Properties.Settings.Default.Save();

proxyAddress = Properties.Settings.Default.proxy;
}
}
}

private void tokenLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.Hide();

TokenLogin token = new TokenLogin(this);

token.Show();
System.Diagnostics.Process.Start("https://discord.gg/naticord");
}
}
}

135 changes: 8 additions & 127 deletions Naticord/Forms/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 552a454

Please sign in to comment.