I am lost
For some reason whenever I press enter, nothing happens, the MK_content doesn't get written into the file.
95 Replies
have you set a breakpoint and verified that your code runs as expected?
Runs as expected?
Also yea, I did breakpoints
But for some reason it just doesn't write text into the file
but it does hit the
File.WriteAllText(MK_path, MK_content);
line, and MK_content
has a non-null non-empty value at that point?
you verified this with the debugger?How do I see variables in debug mode?
Hmm... MK content is null
only time you set it is when reading from the file
so if the file doesnt exist, you write null to it š®
It's a WPF
And file exists
and its non-empty?
again, set a breakpoint on the load and verify
Oh right, I should probably update you on my code
breakpoint + debugging = the way to go
I fixed the issue with if (!string.IsNullOrEmpty(MK_content))
the code you pasted does not contain any
string.INOE
fyistring.INOE?
IsNullOrEmpty
I know
This is just creating the MK
It's supposed to be empty
Basically the purpose of this is to check whetehr MK exists, it doesn't, so I create MK and save it into the file
But the problem is it doesn't save to the file
where exactly do you "create the MK"?
again, nowhere do you assign a value to that variable
it will never not be null or
""
using (File.Create(MK_path)) { }
yeah that makes an empty file
Yea, it;s supposed to be empty
After creation I want for user to input a value and that value gets saved into that
So I can move to MK_login
you uh... don't need that :p
its trivial to create a file when writing to it, if it doesnt already exist
oh, so what you're saying I should move the creation of the fil
I found something even worse
f (MK_exists)
{
sp_MK_Login.Visibility = Visibility.Visible;
}
else
{
sp_MK_creation.Visibility = Visibility.Visible;
}
This doesn't even work
your code is very hard to read btw
Why?
random indentations and blank lines, terrible variable names
Variables would be really long
otherwise
filePath
fileContent
you can (and should) also create methods to separate your code into blocks that have separate purposes
and don't do file-io in a class constructor :dFile-io?
file input/output
ie, reading or writing to a file
Then what am I supposed to do
š
I'll probably... just restart the project
describe to me exactly what is going on here.
On startup, you want to know if a masterkey is set or not?
Gimme second
and if not, prompt the user for one and save it, yeah?
In the beginning I am trying to learn whether masterKey exists or not.
If it doesn't, I prompt user to create one. User enters the value into passwordbox and presses enter, the masterkey gets saved. After that a new window gets opened with accounts and passwords to them. On consecutive launches it prompts user to login, aka enter masterkey they had made which then opens the window with accounts and passwords
how does the prompt work?
hm?
is it a separate window? a popup?
A window
separate window?
Ye
I currently don't have a window for accounts and passwords...
okay.
I am not that far
<Window x:Class="Password_Manager.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Password_Manager"
mc:Ignorable="d"
Title="Login Window" Height="450" Width="800">
<Grid>
<TextBox HorizontalAlignment="Left" Width="120" Height="120" Cursor="IBeam"></TextBox>
<!-- Login Window-->
<StackPanel Name="sp_MK_Login" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Hidden">
<TextBlock Name="tb_MK_login" Text="Enter your MasterKey" FontSize="20"></TextBlock>
<PasswordBox Name ="PasswordBox_MK_Login" Width="120" Height="20" IsEnabled="True"></PasswordBox>
</StackPanel>
<!-- MK creation Window-->
<StackPanel Name="sp_MK_creation" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Hidden">
<TextBlock Name="tb_MK_creation" Text="Create your MasterKey" FontSize="20"></TextBlock>
<PasswordBox Name="PasswordBox_MK_Creation" Width="120" Height="20" IsEnabled="True" Focusable="True" Cursor="IBeam"></PasswordBox>
</StackPanel>
<Label Name="debug_label" Content="" Width="120" Height="15" HorizontalAlignment="Right"></Label>
</Grid>
</Window>
you're building something similar to KeePass right?
Ye
Had a small sketch
The "after user choice" it displays the box with password
I'd probably code this as actually loading the main window first, then immediately on load check if the masterkey exists or not
if not, show a dialog that must be answered before you can interact with the main window
Fair, but I have no idea how to make these
you just make a normal window and show it with
.ShowDialog
I'll probably restart the project as I've already made a massive mess out of it
what do you think about something like this?
What's keycore?
something I just came up with.
in this case, its a static class that keeps track of the master key
Sounds nice
But am still hellishly confused where to even start
well, with the code I just gave you is a pretty good start
then just hooking up that
Window_loaded
event in your xaml
then implementing the missing classes and methodsOn the note of you saying I should make the file once user inputs the value, how would I go about that?
Do I just make multiple Windows?
internal?
thats my implementation of
SetMasterKey
š
it does just that
if the file exist, it overwrites
if it doesnt, it creates
as easy as thatWoudln't that be problematic?
why?
dunno, overwriting masterkey every single time...
someone called "SetMasterKey"
well, its not
the only way to call that method currently is if the file doesnt exist
my brain too dumb š
only if
TryLoadMasterKey()
returns false do we actually call KeyCore.SetMasterKey
I just can't wrap my head around it I guess...
what in particular is it you cant understand atm?
Probably everything, I don't know where to start, just too many methods
well I've given you a fairly solid beginning atm
I know that
And now I am stuck
;-;
@Pobiega Why isn't it displaying there?
I'm not sure if WPF allows you to show a dialog without having a window shown already. Maybe maybe not.
Either way I run into another weird problem
For some reason main window does not open
you're doing way too much stuff here
the whole conditional loading of windows thing you have going on makes me feel very uneasy
cmon, it's not that bad
you should have seen my first game's code
probably not š
anyways, any idea why it just... doesn't work?
The program stops when I enter correct password
mhm
because you killed your only window
oh right
a WPF/winforms app must at all times have a window active, or it terminates
I miss the enter button void
Now I forgot how to do it
How would you do "When enter is pressed, the login confirms"
https://stackoverflow.com/questions/4194470/how-to-make-a-submit-button-in-wpf
set the
IsDefault
property on a button
anyways, gonna sleepnooo
gl with your stuff. stop doing conditional creation of your primary form :p
I have 6 hours to finish this
This makes me realize I already spent 5 hours and I haven't even started
š¤
... you start 11 hours before the final deadline?
bold move cotton, lets see if it pays off
It's not that
Teached gave us the assignment today
He wants it submitted tommorow
thats a pretty rough timeline
you tell me
I have to learn whole wpf, make a code, design in a single day
ĀÆ\_(ć)_/ĀÆ
stop overcomplicating things with your nested ifs everywhere
I have no idea what you mean by that š
having 8 branches in your app startup is a massive codesmell
I think it makes it easier
Man, I had 98 ifs in a row
In some code
Each of them contain from 1 to 4 another ifs
that seems way too many to ever be good
but i digress
Got full points
ĀÆ\_(ć)_/ĀÆ
button does not work
š
š¤
good night