main: Added encryption and login

This commit is contained in:
Nathan Woodburn 2023-07-05 17:38:25 +10:00
parent 5b4dd082af
commit 9e2a1c17d8
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
5 changed files with 205 additions and 33 deletions

View File

@ -33,6 +33,10 @@
label1 = new Label();
label2 = new Label();
textBoxSeed = new TextBox();
label3 = new Label();
textBoxPassword = new TextBox();
textBoxPassword2 = new TextBox();
label4 = new Label();
SuspendLayout();
//
// button1
@ -45,6 +49,7 @@
button1.TabIndex = 0;
button1.Text = "Start";
button1.UseVisualStyleBackColor = true;
button1.Click += Start_Click;
//
// label1
//
@ -59,27 +64,68 @@
// label2
//
label2.AutoSize = true;
label2.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point);
label2.Location = new Point(12, 51);
label2.Name = "label2";
label2.Size = new Size(303, 45);
label2.Size = new Size(350, 57);
label2.TabIndex = 2;
label2.Text = "Here is your seed phrase:\r\nYou should save this somewhere safe (preferably offline)\r\nThis will not be shown again";
//
// textBoxSeed
//
textBoxSeed.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point);
textBoxSeed.Location = new Point(12, 99);
textBoxSeed.Location = new Point(12, 111);
textBoxSeed.Multiline = true;
textBoxSeed.Name = "textBoxSeed";
textBoxSeed.ReadOnly = true;
textBoxSeed.Size = new Size(756, 140);
textBoxSeed.Size = new Size(756, 128);
textBoxSeed.TabIndex = 3;
//
// label3
//
label3.AutoSize = true;
label3.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point);
label3.Location = new Point(12, 270);
label3.Name = "label3";
label3.Size = new Size(125, 19);
label3.TabIndex = 4;
label3.Text = "Create a password:";
//
// textBox1
//
textBoxPassword.Location = new Point(143, 269);
textBoxPassword.Name = "textBox1";
textBoxPassword.Size = new Size(182, 23);
textBoxPassword.TabIndex = 5;
textBoxPassword.UseSystemPasswordChar = true;
//
// textBox2
//
textBoxPassword2.Location = new Point(143, 298);
textBoxPassword2.Name = "textBox2";
textBoxPassword2.Size = new Size(182, 23);
textBoxPassword2.TabIndex = 6;
textBoxPassword2.UseSystemPasswordChar = true;
//
// label4
//
label4.AutoSize = true;
label4.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point);
label4.Location = new Point(12, 299);
label4.Name = "label4";
label4.Size = new Size(123, 19);
label4.TabIndex = 4;
label4.Text = "Confirm password:";
//
// FirstLoginForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(780, 450);
Controls.Add(textBoxPassword2);
Controls.Add(textBoxPassword);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(textBoxSeed);
Controls.Add(label2);
Controls.Add(label1);
@ -100,5 +146,9 @@
private Label label1;
private Label label2;
private TextBox textBoxSeed;
private Label label3;
private TextBox textBoxPassword;
private TextBox textBoxPassword2;
private Label label4;
}
}

View File

@ -7,16 +7,20 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FireWallet;
using Newtonsoft.Json.Linq;
namespace FireWalletLite
{
public partial class FirstLoginForm : Form
{
String seedPhrase;
MainForm main;
public FirstLoginForm(string seedPhrase, MainForm mainForm)
{
InitializeComponent();
this.seedPhrase = seedPhrase;
this.main = mainForm;
// Theme form
this.BackColor = ColorTranslator.FromHtml(mainForm.Theme["background"]);
this.ForeColor = ColorTranslator.FromHtml(mainForm.Theme["foreground"]);
@ -26,5 +30,39 @@ namespace FireWalletLite
}
textBoxSeed.Text = seedPhrase;
}
private async void Start_Click(object sender, EventArgs e)
{
if (textBoxPassword.Text.Length < 8)
{
NotifyForm notifyForm = new NotifyForm("Please choose a longer password!");
notifyForm.ShowDialog();
notifyForm.Dispose();
return;
}
if (textBoxPassword.Text != textBoxPassword2.Text)
{
NotifyForm notifyForm = new NotifyForm("Passwords do not match!");
notifyForm.ShowDialog();
notifyForm.Dispose();
return;
}
// Encrypt wallet
string content = "{\"method\":\"encryptwallet\",\"params\":[\"" + textBoxPassword.Text + "\"]}";
string response = await main.APIPost("",true,content);
main.AddLog("Encrypt wallet: " + response);
JObject jObject = JObject.Parse(response);
if (jObject["error"].ToString() != "")
{
NotifyForm notifyForm = new NotifyForm("Error encrypting wallet: " + jObject["error"].ToString());
notifyForm.ShowDialog();
notifyForm.Dispose();
return;
} else
{
this.Close();
}
}
}
}

View File

@ -8,7 +8,7 @@ namespace FireWalletLite
public partial class Loader : Form
{
#region Constants
MainForm mainForm;
MainForm mainForm = new MainForm();
bool hideScreen = false;
Process HSDProcess;
#endregion
@ -16,7 +16,6 @@ namespace FireWalletLite
public Loader()
{
InitializeComponent();
mainForm = new MainForm();
SplashScreen splashScreen = new SplashScreen(false);
splashScreen.Show();
@ -75,32 +74,11 @@ namespace FireWalletLite
private void Loader_Load(object sender, EventArgs e)
{
this.Hide();
mainForm.ShowDialog();
// Close HSD
if (HSDProcess != null)
{
try
{
HSDProcess.Kill();
Thread.Sleep(1000);
}
catch
{
Environment.Exit(90);
}
try
{
HSDProcess.Dispose();
}
catch
{
Environment.Exit(90);
}
}
Environment.Exit(0);
this.ShowInTaskbar = false;
this.Opacity = 0;
}
#region Git
public void CloneRepository(string repositoryUrl, string destinationPath)
{

View File

@ -33,7 +33,13 @@
statusStripMain = new StatusStrip();
SyncLabel = new ToolStripStatusLabel();
timerUpdate = new System.Windows.Forms.Timer(components);
panelLogin = new Panel();
labelWelcome = new Label();
textBoxPassword = new TextBox();
labelPassword = new Label();
LoginButton = new Button();
statusStripMain.SuspendLayout();
panelLogin.SuspendLayout();
SuspendLayout();
//
// statusStripMain
@ -43,7 +49,7 @@
statusStripMain.Location = new Point(0, 0);
statusStripMain.Name = "statusStripMain";
statusStripMain.RenderMode = ToolStripRenderMode.Professional;
statusStripMain.Size = new Size(800, 22);
statusStripMain.Size = new Size(784, 22);
statusStripMain.TabIndex = 0;
statusStripMain.Text = "statusStrip1";
//
@ -56,23 +62,80 @@
// timerUpdate
//
timerUpdate.Enabled = true;
timerUpdate.Interval = 1000;
timerUpdate.Interval = 10000;
timerUpdate.Tick += timerUpdate_Tick;
//
// panelLogin
//
panelLogin.Controls.Add(labelWelcome);
panelLogin.Controls.Add(textBoxPassword);
panelLogin.Controls.Add(labelPassword);
panelLogin.Controls.Add(LoginButton);
panelLogin.Dock = DockStyle.Fill;
panelLogin.Location = new Point(0, 22);
panelLogin.Name = "panelLogin";
panelLogin.Size = new Size(784, 428);
panelLogin.TabIndex = 1;
//
// labelWelcome
//
labelWelcome.AutoSize = true;
labelWelcome.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point);
labelWelcome.Location = new Point(341, 143);
labelWelcome.Name = "labelWelcome";
labelWelcome.Size = new Size(118, 25);
labelWelcome.TabIndex = 3;
labelWelcome.Text = "Please Login";
//
// textBoxPassword
//
textBoxPassword.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
textBoxPassword.Location = new Point(384, 201);
textBoxPassword.Name = "textBoxPassword";
textBoxPassword.Size = new Size(137, 29);
textBoxPassword.TabIndex = 2;
textBoxPassword.UseSystemPasswordChar = true;
//
// labelPassword
//
labelPassword.AutoSize = true;
labelPassword.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelPassword.Location = new Point(299, 204);
labelPassword.Name = "labelPassword";
labelPassword.Size = new Size(79, 21);
labelPassword.TabIndex = 1;
labelPassword.Text = "Password:";
//
// LoginButton
//
LoginButton.FlatStyle = FlatStyle.Flat;
LoginButton.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
LoginButton.Location = new Point(335, 300);
LoginButton.Name = "LoginButton";
LoginButton.Size = new Size(130, 37);
LoginButton.TabIndex = 0;
LoginButton.Text = "Login";
LoginButton.UseVisualStyleBackColor = true;
LoginButton.Click += Login_Click;
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(784, 450);
Controls.Add(panelLogin);
Controls.Add(statusStripMain);
Icon = (Icon)resources.GetObject("$this.Icon");
MaximizeBox = false;
MinimizeBox = false;
Name = "MainForm";
Text = "MainForm";
FormClosing += MainForm_FormClosing;
Load += MainForm_Load;
statusStripMain.ResumeLayout(false);
statusStripMain.PerformLayout();
panelLogin.ResumeLayout(false);
panelLogin.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
@ -82,5 +145,10 @@
private StatusStrip statusStripMain;
private ToolStripStatusLabel SyncLabel;
private System.Windows.Forms.Timer timerUpdate;
private Panel panelLogin;
private Button LoginButton;
private Label labelWelcome;
private TextBox textBoxPassword;
private Label labelPassword;
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
@ -268,7 +269,12 @@ namespace FireWalletLite
private void MainForm_Load(object sender, EventArgs e)
{
LoginButton.Left = (this.ClientSize.Width - LoginButton.Width) / 2;
int widthOfPassword = textBoxPassword.Width + labelPassword.Width;
labelPassword.Left = (this.ClientSize.Width - widthOfPassword) / 2;
textBoxPassword.Left = labelPassword.Right;
labelWelcome.Left = (this.ClientSize.Width - labelWelcome.Width) / 2;
textBoxPassword.Focus();
}
private async void TestForLogin()
{
@ -286,5 +292,37 @@ namespace FireWalletLite
firstLoginForm.Dispose();
}
}
private async void Login_Click(object sender, EventArgs e)
{
LoginButton.Enabled = false; // To prevent double clicking
Password = textBoxPassword.Text;
string path = "wallet/" + Account + "/unlock";
string content = "{\"passphrase\": \"" + Password + "\",\"timeout\": 60}";
string response = await APIPost(path, true, content);
if (response.Contains("Could not decrypt"))
{
Password = "";
NotifyForm notifyForm = new NotifyForm("Incorrect Password");
notifyForm.ShowDialog();
notifyForm.Dispose();
LoginButton.Enabled = true;
}
panelLogin.Hide();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
// Run taskkill /im "node.exe" /f /t
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "taskkill.exe";
startInfo.Arguments = "/im \"node.exe\" /f /t";
startInfo.CreateNoWindow = true;
Process.Start(startInfo);
Environment.Exit(0);
}
}
}