© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
165 replies
Nadekai

I am lost

For some reason whenever I press enter, nothing happens, the MK_content doesn't get written into the file.

using System;
using System.Collections.Generic;
using System.IO;


namespace Password_Manager
{
    
    public partial class MainWindow : Window
    {
        public bool MK_exists = false;
        public string MK_content = null;
        public string MK_path = "Data\\MasterKey.txt";
        public MainWindow()
        {
            InitializeComponent();

            // Accessing variables
            

            

            if (File.Exists(MK_path))
            {
                // Check if MasterKey.txt exists and has content
                if (new FileInfo(MK_path).Length > 0)
                {
                    MK_exists = true;
                    MK_content = File.ReadAllText(MK_path); // Read the content of MasterKey.txt
                }
            }
            else
            {
                // Create MasterKey.txt if it doesn't exist
                using (File.Create(MK_path)) { }
            }

            // Show the appropriate stack panel based on MK existence
            if (MK_exists)
            {
                sp_MK_Login.Visibility = Visibility.Visible;
            }
            else
            {
                sp_MK_creation.Visibility = Visibility.Visible;
            }

            // Set the content of the password box if MK_content is not null or empty
           

            debug_label.Content = MK_content;

            tb_MK_PasswordBox_Creation.KeyDown += MK_PB_Creation_KeyDown;
        }

        private void MK_PB_Creation_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.Enter)
            {
                if (!string.IsNullOrEmpty(MK_content))
                {

                    tb_MK_PasswordBox_Creation.Password = MK_content;
                    File.WriteAllText(MK_path, MK_content);
                }
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.IO;


namespace Password_Manager
{
    
    public partial class MainWindow : Window
    {
        public bool MK_exists = false;
        public string MK_content = null;
        public string MK_path = "Data\\MasterKey.txt";
        public MainWindow()
        {
            InitializeComponent();

            // Accessing variables
            

            

            if (File.Exists(MK_path))
            {
                // Check if MasterKey.txt exists and has content
                if (new FileInfo(MK_path).Length > 0)
                {
                    MK_exists = true;
                    MK_content = File.ReadAllText(MK_path); // Read the content of MasterKey.txt
                }
            }
            else
            {
                // Create MasterKey.txt if it doesn't exist
                using (File.Create(MK_path)) { }
            }

            // Show the appropriate stack panel based on MK existence
            if (MK_exists)
            {
                sp_MK_Login.Visibility = Visibility.Visible;
            }
            else
            {
                sp_MK_creation.Visibility = Visibility.Visible;
            }

            // Set the content of the password box if MK_content is not null or empty
           

            debug_label.Content = MK_content;

            tb_MK_PasswordBox_Creation.KeyDown += MK_PB_Creation_KeyDown;
        }

        private void MK_PB_Creation_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.Enter)
            {
                if (!string.IsNullOrEmpty(MK_content))
                {

                    tb_MK_PasswordBox_Creation.Password = MK_content;
                    File.WriteAllText(MK_path, MK_content);
                }
            }
        }
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Next page

Similar Threads

I feel i am lost
C#CC# / help
7mo ago
❔ I am Kinda lost right now
C#CC# / help
3y ago
✅ i am new
C#CC# / help
9mo ago
i am stuck
C#CC# / help
3y ago