Ejemplo n.º 1
0
        private void Button_CreateUser_Click(object sender, EventArgs e)
        {
            Usercontol_Sidepanel_Chooseuser uscho = new Usercontol_Sidepanel_Chooseuser();
            Form_Main fm = new Form_Main();

            if (!string.IsNullOrWhiteSpace(Textbox_Name.Text))
            {
                CasedLetter = Textbox_Name.Text.Substring(0, 1).ToUpper();
                RestName    = Textbox_Name.Text.Substring(1, Textbox_Name.Text.Length - 1).ToLower();
            }

            CasedName = CasedLetter + RestName;

            CreateUser(CasedName, Textbox_Password.Text);
        }
Ejemplo n.º 2
0
        public void CreateUser(string name, string password)
        {
            Usercontol_Sidepanel_Chooseuser uschu = new Usercontol_Sidepanel_Chooseuser();
            Form_Main fm = new Form_Main();

            if (string.IsNullOrWhiteSpace(Textbox_Name.Text) || string.IsNullOrWhiteSpace(Textbox_Password.Text))
            {
                Label_Error.Text = "Reenter username/password";
                return;
            }
            else if (Form_Main.Users.Count == 3)
            {
                Label_Error.Text = "Maximum user count reached";
                return;
            }
            else if (Directory.Exists("@" + name.ToLower()))
            {
                Label_Error.Text = "User already exists";
                return;
            }
            else if (!Directory.Exists("@" + name.ToLower()) && Form_Main.Users.Count != 3)
            {
                Directory.CreateDirectory("@" + name.ToLower());
                string       BaseDirectory = "@" + name.ToLower();
                string       FileDirectory = "#" + name.ToLower();
                StreamWriter sp            = new StreamWriter(Path.Combine(BaseDirectory, FileDirectory) + "p");
                sp.Write(password);
                sp.Flush();
                sp.Close();
                StreamWriter sn = new StreamWriter(Path.Combine(BaseDirectory, FileDirectory) + "n");
                sn.Write(name);
                sn.Flush();
                sn.Close();
                File.Encrypt(Path.Combine(BaseDirectory, FileDirectory) + "p");
                File.Encrypt(Path.Combine(BaseDirectory, FileDirectory) + "n");
                Form_Main.Main.LogIn(name, password);
            }
        }