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(); label1 = new Label();
label2 = new Label(); label2 = new Label();
textBoxSeed = new TextBox(); textBoxSeed = new TextBox();
label3 = new Label();
textBoxPassword = new TextBox();
textBoxPassword2 = new TextBox();
label4 = new Label();
SuspendLayout(); SuspendLayout();
// //
// button1 // button1
@ -45,6 +49,7 @@
button1.TabIndex = 0; button1.TabIndex = 0;
button1.Text = "Start"; button1.Text = "Start";
button1.UseVisualStyleBackColor = true; button1.UseVisualStyleBackColor = true;
button1.Click += Start_Click;
// //
// label1 // label1
// //
@ -59,27 +64,68 @@
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point);
label2.Location = new Point(12, 51); label2.Location = new Point(12, 51);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(303, 45); label2.Size = new Size(350, 57);
label2.TabIndex = 2; 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"; 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
// //
textBoxSeed.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point); 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.Multiline = true;
textBoxSeed.Name = "textBoxSeed"; textBoxSeed.Name = "textBoxSeed";
textBoxSeed.ReadOnly = true; textBoxSeed.ReadOnly = true;
textBoxSeed.Size = new Size(756, 140); textBoxSeed.Size = new Size(756, 128);
textBoxSeed.TabIndex = 3; 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 // FirstLoginForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(780, 450); ClientSize = new Size(780, 450);
Controls.Add(textBoxPassword2);
Controls.Add(textBoxPassword);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(textBoxSeed); Controls.Add(textBoxSeed);
Controls.Add(label2); Controls.Add(label2);
Controls.Add(label1); Controls.Add(label1);
@ -100,5 +146,9 @@
private Label label1; private Label label1;
private Label label2; private Label label2;
private TextBox textBoxSeed; 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.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using FireWallet;
using Newtonsoft.Json.Linq;
namespace FireWalletLite namespace FireWalletLite
{ {
public partial class FirstLoginForm : Form public partial class FirstLoginForm : Form
{ {
String seedPhrase; String seedPhrase;
MainForm main;
public FirstLoginForm(string seedPhrase, MainForm mainForm) public FirstLoginForm(string seedPhrase, MainForm mainForm)
{ {
InitializeComponent(); InitializeComponent();
this.seedPhrase = seedPhrase; this.seedPhrase = seedPhrase;
this.main = mainForm;
// Theme form // Theme form
this.BackColor = ColorTranslator.FromHtml(mainForm.Theme["background"]); this.BackColor = ColorTranslator.FromHtml(mainForm.Theme["background"]);
this.ForeColor = ColorTranslator.FromHtml(mainForm.Theme["foreground"]); this.ForeColor = ColorTranslator.FromHtml(mainForm.Theme["foreground"]);
@ -26,5 +30,39 @@ namespace FireWalletLite
} }
textBoxSeed.Text = seedPhrase; 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 public partial class Loader : Form
{ {
#region Constants #region Constants
MainForm mainForm; MainForm mainForm = new MainForm();
bool hideScreen = false; bool hideScreen = false;
Process HSDProcess; Process HSDProcess;
#endregion #endregion
@ -16,7 +16,6 @@ namespace FireWalletLite
public Loader() public Loader()
{ {
InitializeComponent(); InitializeComponent();
mainForm = new MainForm();
SplashScreen splashScreen = new SplashScreen(false); SplashScreen splashScreen = new SplashScreen(false);
splashScreen.Show(); splashScreen.Show();
@ -75,32 +74,11 @@ namespace FireWalletLite
private void Loader_Load(object sender, EventArgs e) private void Loader_Load(object sender, EventArgs e)
{ {
this.Hide(); this.ShowInTaskbar = false;
mainForm.ShowDialog(); this.Opacity = 0;
// 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);
} }
#region Git #region Git
public void CloneRepository(string repositoryUrl, string destinationPath) public void CloneRepository(string repositoryUrl, string destinationPath)
{ {

View File

@ -33,7 +33,13 @@
statusStripMain = new StatusStrip(); statusStripMain = new StatusStrip();
SyncLabel = new ToolStripStatusLabel(); SyncLabel = new ToolStripStatusLabel();
timerUpdate = new System.Windows.Forms.Timer(components); timerUpdate = new System.Windows.Forms.Timer(components);
panelLogin = new Panel();
labelWelcome = new Label();
textBoxPassword = new TextBox();
labelPassword = new Label();
LoginButton = new Button();
statusStripMain.SuspendLayout(); statusStripMain.SuspendLayout();
panelLogin.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// statusStripMain // statusStripMain
@ -43,7 +49,7 @@
statusStripMain.Location = new Point(0, 0); statusStripMain.Location = new Point(0, 0);
statusStripMain.Name = "statusStripMain"; statusStripMain.Name = "statusStripMain";
statusStripMain.RenderMode = ToolStripRenderMode.Professional; statusStripMain.RenderMode = ToolStripRenderMode.Professional;
statusStripMain.Size = new Size(800, 22); statusStripMain.Size = new Size(784, 22);
statusStripMain.TabIndex = 0; statusStripMain.TabIndex = 0;
statusStripMain.Text = "statusStrip1"; statusStripMain.Text = "statusStrip1";
// //
@ -56,23 +62,80 @@
// timerUpdate // timerUpdate
// //
timerUpdate.Enabled = true; timerUpdate.Enabled = true;
timerUpdate.Interval = 1000; timerUpdate.Interval = 10000;
timerUpdate.Tick += timerUpdate_Tick; 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 // MainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(784, 450);
Controls.Add(panelLogin);
Controls.Add(statusStripMain); Controls.Add(statusStripMain);
Icon = (Icon)resources.GetObject("$this.Icon"); Icon = (Icon)resources.GetObject("$this.Icon");
MaximizeBox = false; MaximizeBox = false;
MinimizeBox = false; MinimizeBox = false;
Name = "MainForm"; Name = "MainForm";
Text = "MainForm"; Text = "MainForm";
FormClosing += MainForm_FormClosing;
Load += MainForm_Load; Load += MainForm_Load;
statusStripMain.ResumeLayout(false); statusStripMain.ResumeLayout(false);
statusStripMain.PerformLayout(); statusStripMain.PerformLayout();
panelLogin.ResumeLayout(false);
panelLogin.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -82,5 +145,10 @@
private StatusStrip statusStripMain; private StatusStrip statusStripMain;
private ToolStripStatusLabel SyncLabel; private ToolStripStatusLabel SyncLabel;
private System.Windows.Forms.Timer timerUpdate; 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.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -268,7 +269,12 @@ namespace FireWalletLite
private void MainForm_Load(object sender, EventArgs e) 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() private async void TestForLogin()
{ {
@ -286,5 +292,37 @@ namespace FireWalletLite
firstLoginForm.Dispose(); 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);
}
} }
} }