C
C#7mo ago
Nadekai

✅ Lost again

After entering password and hitting enter, another login window opens, if I close all login windows, if the password was correct, it opens 2 main windows instead of 1.
122 Replies
Nadekai
NadekaiOP7mo ago
login.xaml.cs
c#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Password_manager
{
/// <summary>
/// Interaction logic for Login.xaml
/// </summary>
public partial class Login : Window
{

public Login()
{
InitializeComponent();
}
private void KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
string MasterKey = File.ReadAllText("Data\\MasterKey.txt");

Login login = new Login();
login.KeyDown += KeyPress;
login.ShowDialog();
}
}
}
}
c#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Password_manager
{
/// <summary>
/// Interaction logic for Login.xaml
/// </summary>
public partial class Login : Window
{

public Login()
{
InitializeComponent();
}
private void KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
string MasterKey = File.ReadAllText("Data\\MasterKey.txt");

Login login = new Login();
login.KeyDown += KeyPress;
login.ShowDialog();
}
}
}
}
app.xaml.cs
c#
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;

namespace Password_manager
{
public partial class App : Application
{
private int debugInt = 0;
private const string MasterKeyFilePath = "Data\\masterkey.txt";
private string MasterKey;

protected override void OnStartup(StartupEventArgs e)
{
debugInt++;
base.OnStartup(e);

if (!MasterKeyExists())
{
if (!Directory.Exists("Data"))
{
// If master key doesn't exist and directory doesn't exist, prompt the user to create one
MasterKeyPrompt masterKeyPrompt = new MasterKeyPrompt();
masterKeyPrompt.ShowDialog();

// Save the master key
Directory.CreateDirectory("Data");
MasterKey = masterKeyPrompt.PasswordBox.Password;
SaveMasterKey(MasterKey);
}
}
else
{
MasterKey = File.ReadAllText(MasterKeyFilePath);
// Prompt for login
Login login = new Login();
login.KeyDown += KeyPress; // Hook up the KeyDown event
login.ShowDialog();
}
}

private bool MasterKeyExists()
{
return File.Exists(MasterKeyFilePath);
}

private void SaveMasterKey(string masterKey)
{
File.WriteAllText(MasterKeyFilePath, masterKey);
}


c#
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;

namespace Password_manager
{
public partial class App : Application
{
private int debugInt = 0;
private const string MasterKeyFilePath = "Data\\masterkey.txt";
private string MasterKey;

protected override void OnStartup(StartupEventArgs e)
{
debugInt++;
base.OnStartup(e);

if (!MasterKeyExists())
{
if (!Directory.Exists("Data"))
{
// If master key doesn't exist and directory doesn't exist, prompt the user to create one
MasterKeyPrompt masterKeyPrompt = new MasterKeyPrompt();
masterKeyPrompt.ShowDialog();

// Save the master key
Directory.CreateDirectory("Data");
MasterKey = masterKeyPrompt.PasswordBox.Password;
SaveMasterKey(MasterKey);
}
}
else
{
MasterKey = File.ReadAllText(MasterKeyFilePath);
// Prompt for login
Login login = new Login();
login.KeyDown += KeyPress; // Hook up the KeyDown event
login.ShowDialog();
}
}

private bool MasterKeyExists()
{
return File.Exists(MasterKeyFilePath);
}

private void SaveMasterKey(string masterKey)
{
File.WriteAllText(MasterKeyFilePath, masterKey);
}


c#


private void KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return) // Check if Enter key is pressed
{
if (sender is Login login)
{
if (login.PasswordBox.Password == MasterKey)
{
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
((Login)sender).Close(); // Close the login window
}
else
{
MessageBox.Show("Incorrect MasterKey.", "Error", MessageBoxButton.OK);
}
}
}
}
}
}
c#


private void KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return) // Check if Enter key is pressed
{
if (sender is Login login)
{
if (login.PasswordBox.Password == MasterKey)
{
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
((Login)sender).Close(); // Close the login window
}
else
{
MessageBox.Show("Incorrect MasterKey.", "Error", MessageBoxButton.OK);
}
}
}
}
}
}
jetblacksalvation
check if password is not "" keypress to keydown is better fitting here but not sure if its in c#
Nadekai
NadekaiOP7mo ago
it isnt password is test
jetblacksalvation
holdpress enter for 10 secs
Nadekai
NadekaiOP7mo ago
with or without the password?
jetblacksalvation
tell me what happens after. I believe this will cause many windows to open
Nadekai
NadekaiOP7mo ago
No description
jetblacksalvation
Yup knew it ignore enter, and add keydown heydown u handle enter
Nadekai
NadekaiOP7mo ago
eh?
jetblacksalvation
Keydown is only called once per button click, this is common in most langs that will fix the tons of windows But work is not finished here
Nadekai
NadekaiOP7mo ago
Yea, but where?
jetblacksalvation
anywhere in thsi class ig
Nadekai
NadekaiOP7mo ago
I have... multiple of them containing keypress
jetblacksalvation
hmm
Nadekai
NadekaiOP7mo ago
removing either of them gives error
jetblacksalvation
Is this on github
Nadekai
NadekaiOP7mo ago
no should I commit?
jetblacksalvation
if u do ill take a look via local Ah but this meant for windows… damn i really dont want to have to run visual studio on my VM
Nadekai
NadekaiOP7mo ago
Processing files ah, a fellow mac user
jetblacksalvation
nah linux
jetblacksalvation
if i run windows i procrastinate too much
Nadekai
NadekaiOP7mo ago
lmao
jetblacksalvation
play too much fortnite If its macos than i should have no issue running. Unless u do it outside of terminal
Nadekai
NadekaiOP7mo ago
It's WPF so...
jetblacksalvation
WPF? Is that an IDE?
Nadekai
NadekaiOP7mo ago
Sent ya invite on gh Windows Something FOrms
jetblacksalvation
Yeah i saw ill accept it Oh. Hmm how odd. If this uses windows’ window api than it shouldnt run on mac os
Nadekai
NadekaiOP7mo ago
Also yes, I am cretin, I should have chosen avalonia Ye, I am doing it on my main pc instead of mac book
jetblacksalvation
oh. So it is windows. Ok, ill need to test my new hard drive and start setting up dual boot. I should have my investigation into ur code done sometime tomorrow
Nadekai
NadekaiOP7mo ago
oof I will probably get fix by then I have deadline in 6 hours
jetblacksalvation
oh damn
Nadekai
NadekaiOP7mo ago
Had 12 hours to learn WPF and make a functional code
jetblacksalvation
I guess i have to run this in my windows vm 🥲 with my 16 gb of ram
Nadekai
NadekaiOP7mo ago
Gotta love when teachers forget we have personal life Had to skip work too 16gb ain't that bad I have 16 gb on my mac But mac handles ram better overally so I wouldn't know My main has 128gb
jetblacksalvation
for vms its not that good
Nadekai
NadekaiOP7mo ago
Never had run VM except parallel
jetblacksalvation
You running a server?
Nadekai
NadekaiOP7mo ago
No lmao I am just a chrome user
jetblacksalvation
lmao
Nadekai
NadekaiOP7mo ago
Nothing is gonna limit my experience with chrome Had a 16gb machine few years ago I don;'t think it had ever struggled Unless the situation changed dramatically
jetblacksalvation
16 gb ram is still very good ram just not for vm's or things that use alot of ram
Nadekai
NadekaiOP7mo ago
Fair My mac is usually using most of the ram
jetblacksalvation
ok, vm is up. Now I need to install visual studio
Nadekai
NadekaiOP7mo ago
💀 Just install notepad++
jetblacksalvation
does it work with sln files?
Nadekai
NadekaiOP7mo ago
No idea, I was half joking but visual studio code works with sln files
jetblacksalvation
oh, ok
Nadekai
NadekaiOP7mo ago
though you gotta install the c# extension for it but it's still way faster than download vs22 if you got slow internet
jetblacksalvation
yeah i just cannot run
Nadekai
NadekaiOP7mo ago
what are you using?
jetblacksalvation
linux
Nadekai
NadekaiOP7mo ago
I meant... which ide
jetblacksalvation
vscode
Nadekai
NadekaiOP7mo ago
Hm...
jetblacksalvation
MainWindow mainWindow = new MainWindow(); mainWindow.Show(); this line should only exist once if show removes the old text, than you should go with only having MainWindow once
Nadekai
NadekaiOP7mo ago
I have a feeling something is wrong with this line ((Login)sender).Close(); // Close the login window but it exists only once no?
jetblacksalvation
no
Nadekai
NadekaiOP7mo ago
Where is it duplicated?
jetblacksalvation
we just proved it here MainWindow mainWindow = new MainWindow();
Nadekai
NadekaiOP7mo ago
that's Login window Not main window
Nadekai
NadekaiOP7mo ago
Even though main window also gets duplicated
No description
jetblacksalvation
oh so you want login menu to be a seperate window from main?
Nadekai
NadekaiOP7mo ago
No I don't want it to get spammed Gimme second imma show a gif
jetblacksalvation
(Login)sender).Close(); // Close the login window doesnt make much sense too. you arent closing mainwindow unless the goal is to remove the last window
Nadekai
NadekaiOP7mo ago
No description
Nadekai
NadekaiOP7mo ago
This weird crap happens
jetblacksalvation
because of MainWindow mainWindow = new MainWindow();
Nadekai
NadekaiOP7mo ago
It's goal is to close Login window once enter is pressed
jetblacksalvation
if (login.PasswordBox.Password == MasterKey) { MainWindow mainWindow = new MainWindow(); mainWindow.Show(); MainWindow.Close(); // Close the login window } try this
Nadekai
NadekaiOP7mo ago
Nothing
jetblacksalvation
c#
private void KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return) // Check if Enter key is pressed
{
if (sender is Login login)
{
if (login.PasswordBox.Password == MasterKey)
{
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
MainWindow.Close(); // Close the login window
}
else
{
MessageBox.Show("Incorrect MasterKey.", "Error", MessageBoxButton.OK);
}
}
}
}
c#
private void KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return) // Check if Enter key is pressed
{
if (sender is Login login)
{
if (login.PasswordBox.Password == MasterKey)
{
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
MainWindow.Close(); // Close the login window
}
else
{
MessageBox.Show("Incorrect MasterKey.", "Error", MessageBoxButton.OK);
}
}
}
}
oh right hmm
Nadekai
NadekaiOP7mo ago
The window that gets spammed is login window' not mainwindow
jetblacksalvation
ok, than do this. if more than one window is created than it is an issue with keypress
c#
while(true){

MainWindow mainWindow = new MainWindow();
mainWindow.Show();
MainWindow.Close(); // Close the login window
}
c#
while(true){

MainWindow mainWindow = new MainWindow();
mainWindow.Show();
MainWindow.Close(); // Close the login window
}
`
Nadekai
NadekaiOP7mo ago
hah even weirded shit happens
jetblacksalvation
flickering screen is expected. What is happening on your end
Nadekai
NadekaiOP7mo ago
No description
jetblacksalvation
yeah expected
Nadekai
NadekaiOP7mo ago
I also put breakpoint on this line, it never occured
No description
jetblacksalvation
where is that code?
Nadekai
NadekaiOP7mo ago
No description
Nadekai
NadekaiOP7mo ago
was just experiment neither case reaches breakpoint there
Nadekai
NadekaiOP7mo ago
This works
No description
jetblacksalvation
did you put the password in?
Nadekai
NadekaiOP7mo ago
But it instantly closes the newly opened window yea
jetblacksalvation
than sender is Login login is never true or password is never true print the pass word above where you check maybe you are adding the enterkeycode to login.passowrdBox.password
Nadekai
NadekaiOP7mo ago
where do I print it
jetblacksalvation
you can add a watch if you want
Nadekai
NadekaiOP7mo ago
how
jetblacksalvation
abve the if statement
Nadekai
NadekaiOP7mo ago
ye, but what command is that
jetblacksalvation
breakpoint than rightclick on the variable you want to watch
Nadekai
NadekaiOP7mo ago
cw?
jetblacksalvation
than click add quick watch when you trigger a breakpoint you right click the variable you want to watch. this is done at runtime
Nadekai
NadekaiOP7mo ago
No description
No description
jetblacksalvation
Set a watch on variables and expressions - Visual Studio (Windows)
While you debug, see variables and expressions in Watch and QuickWatch. Watch can display several variables, QuickWatch only one, and only while in break.
jetblacksalvation
login.PasswordBox.Password change it to this
Nadekai
NadekaiOP7mo ago
It is
jetblacksalvation
no
Nadekai
NadekaiOP7mo ago
oh right
Nadekai
NadekaiOP7mo ago
No description
Nadekai
NadekaiOP7mo ago
the password is correct
jetblacksalvation
put a watch for master key too
Nadekai
NadekaiOP7mo ago
No description
jetblacksalvation
hmmmmmmmmmmmm than sender is Login login is never true
Nadekai
NadekaiOP7mo ago
it breakpointed
jetblacksalvation
put a breakpoint under it and try t
Nadekai
NadekaiOP7mo ago
No description
jetblacksalvation
hmm
Nadekai
NadekaiOP7mo ago
But I have to manually click on "close" for it to activate
jetblacksalvation
replace with login.Close()
Nadekai
NadekaiOP7mo ago
tried
Nadekai
NadekaiOP7mo ago
No description
jetblacksalvation
c#
private void KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return) // Check if Enter key is pressed
{
if (sender is Login login)
{
if (login.PasswordBox.Password == MasterKey)

{
mainWindow.Show();
login.Close(); // Close the login window
}
else
{
MessageBox.Show("Incorrect MasterKey.", "Error", MessageBoxButton.OK);
}
}
}
}
c#
private void KeyPress(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return) // Check if Enter key is pressed
{
if (sender is Login login)
{
if (login.PasswordBox.Password == MasterKey)

{
mainWindow.Show();
login.Close(); // Close the login window
}
else
{
MessageBox.Show("Incorrect MasterKey.", "Error", MessageBoxButton.OK);
}
}
}
}
try this actually
Nadekai
NadekaiOP7mo ago
now it doesn't open window also gives error
jetblacksalvation
what's the error
Nadekai
NadekaiOP7mo ago
if I leave it the way you wrote it mainWindow doesn't exist MainWindow does
jetblacksalvation
{ if (e.Key == Key.Return) // Check if Enter key is pressed { if (sender is Login login) { if (login.PasswordBox.Password == MasterKey)
{ login.Close(); // Close the login window } else { MessageBox.Show("Incorrect MasterKey.", "Error", MessageBoxButton.OK); } } } } do this its supposed to close, not display anything right? if the pass is right
Nadekai
NadekaiOP7mo ago
Depends on how you mean it If you mean when pressing enter than old shit happens
Nadekai
NadekaiOP7mo ago
No description
jetblacksalvation
lets get on vc 1
Nadekai
NadekaiOP7mo ago
aye <PasswordBox Name="PasswordBox" Width="300" Height="30" FontSize="30" HorizontalAlignment="Right" Margin="20" KeyDown="KeyPress" ></PasswordBox>
Want results from more Discord servers?
Add your server