I am trying to do a key system that redirects the user to a key that he can copy and put in the textbox to verify but it is freezing when i am trying to generate the link. Here is the code.
using System;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PastebinAPI;
namespace LoginKeyPastebin
{
public partial class Form1 : Form
{
string paste_url = "";
string key = "heydude";
public Form1()
{
InitializeComponent();
textBox1.PasswordChar = '\u25CF';
textBox1.Text = "";
}
static int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
static string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
if (lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}
static string RandomPassword()
{
StringBuilder builder = new StringBuilder();
builder.Append(RandomString(4, true));
builder.Append(RandomNumber(1000, 9999));
builder.Append(RandomString(2, false));
return builder.ToString();
}
public string GetStringFromLink(string link)
{
WebClient client = new WebClient();
string reply = client.DownloadString(link);
return reply;
}
private void SubmitButton_Click(object sender, EventArgs e)
{
string user_key = textBox1.Text;
if (user_key == "mypassword" || user_key == key)
{
//this.Hide();
//ScriptExecutor se = new ScriptExecutor();
//se.ShowDialog();
//this.Close();
MessageBox.Show("You got the right key!", "Yes");
}
else
{
MessageBox.Show("It's not the key!", "NOPE");
}
}
private void GetKeyButton_Click(object sender, EventArgs e)
{
key = RandomPassword();
GetPastebinLink(key).GetAwaiter().GetResult();
System.Diagnostics.Process.Start(paste_url);
}
public async Task GetPastebinLink(string key)
{
Pastebin.DevKey = "mydevkey";
User me = await Pastebin.LoginAsync("myusername", "mypassword");
Paste newPaste = await me.CreatePasteAsync(key, "NewPloit key testing", Language.HTML5, Visibility.Unlisted, Expiration.TenMinutes);
paste_url = newPaste.Url;
}
}
}
I suspect the problem is in the GetPastebinLink() function but i dont know why it is doing it. I ran a similar code but console-based and it worked perfectly.
Can you please help me figuring out the problem and solving it?
Thanks