Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace 秘密檔案
- {
- public partial class Form1 : Form
- {
- //--------------
- //宣告全域變數
- //--------------
- string[] user ;//使用者名稱陣列
- string[] password;//密碼陣列
- string savedUser;//使用者名稱資料暫存(用於縮短程式碼
- string savedPassword;//密碼資料暫存(用於縮短程式碼
- int pos;//暫存陣列位置資訊
- int loginUser = 0;//登入使用者序號
- bool logging;//是否登入中
- bool initializing = true;//初次初始化
- //暫存各使用者資訊
- string[] s = new string[5] { Properties.Settings.Default.slot1, Properties.Settings.Default.slot2, Properties.Settings.Default.slot3, Properties.Settings.Default.slot4, Properties.Settings.Default.slot5};
- string[] userData;//暫存登入中使用者資料
- public Form1()
- {
- InitializeComponent();
- }
- //--------
- //初始化
- //--------
- private void Form1_Load(object sender, EventArgs e)
- {
- textBox3.Text = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//預設目標資料夾位置
- creatFolder(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\topHider");//初次使用本程式,產生隱藏目標資料夾
- savedUser = Properties.Settings.Default.user;//帳戶資料存入暫存
- savedPassword = Properties.Settings.Default.password;//密碼資料存入暫存
- Initialize();
- }
- public void Initialize()//初始化及儲存資料
- {
- pos = 0;//陣列位置序列號歸零
- Properties.Settings.Default.slot1 = s[0];//------------------
- Properties.Settings.Default.slot2 = s[1];//
- Properties.Settings.Default.slot3 = s[2];//儲存各使用者資料
- Properties.Settings.Default.slot4 = s[3];//
- Properties.Settings.Default.slot5 = s[4];//------------------
- Properties.Settings.Default.user = savedUser;//儲存帳戶資料
- Properties.Settings.Default.password = savedPassword;//儲存密碼資料
- Properties.Settings.Default.Save();//存檔
- if (!initializing) { userData = s[loginUser].Split(','); }//初始化登入使用者資料
- user = Properties.Settings.Default.user.Split(',');//初始化帳戶資料
- password = Properties.Settings.Default.password.Split(',');//初始化密碼資料
- initializing = false;
- }
- //----------
- //Function
- //----------
- public bool admin()
- {
- if (textBox1.Text == "admin" && textBox2.Text == "developeroptionon")
- {
- return true;
- }
- return false;
- }
- public void creatFolder(string hidePath)//創建資料夾
- {
- Directory.CreateDirectory(hidePath);
- DirectoryInfo diMyDir = new DirectoryInfo(hidePath);
- diMyDir.Attributes = FileAttributes.Hidden;
- }
- public void moveFolder(string io)//移動資料夾
- {
- DirectoryInfo diMyDir = new DirectoryInfo(textBox3.Text);//設定目標資料夾
- if (diMyDir.Exists)//資料夾是否存在
- {
- if (io == "in")
- {
- diMyDir.Attributes = FileAttributes.Hidden;
- diMyDir.MoveTo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\topHider\" + textBox1.Text + @"\" + diMyDir.Name);
- listBox1.Items.Add(diMyDir.Name);
- s[loginUser] += diMyDir.Name + ",";
- Initialize();
- }
- else
- if (io == "out")
- {
- }
- }
- else
- {
- MessageBox.Show("無此資料夾", "轉移失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- public void deleteAccount(int pos)
- {
- for (int i = pos; i < user.Length-1; i++)
- {
- s[i] = s[i + 1];
- }
- Properties.Settings.Default.slot1 = s[0];
- Properties.Settings.Default.slot2 = s[1];
- Properties.Settings.Default.slot3 = s[2];
- Properties.Settings.Default.slot4 = s[3];
- Properties.Settings.Default.slot5 = s[4];
- Properties.Settings.Default.Save();
- }
- public bool checkPassword()
- {
- for (int t = 0; t < user.Length; t++)//檢測密碼正確
- {
- if (user[t] == textBox1.Text && user.Length >1)
- {
- if (password[t] == textBox2.Text && user.Length > 1)
- {
- pos = t;
- loginUser = t;
- return true;
- }
- }
- }
- return false;
- }
- //----------------
- //主程式(頁籤一)
- //----------------
- private void button1_Click(object sender, EventArgs e)//登入
- {
- if (admin()) { button4.Visible = true; return; }
- if (!logging)
- {
- if (checkPassword())
- {
- loginUser = pos;
- Initialize();
- button1.Text = "登出";
- foreach (string Data in userData)
- {
- if (userData.Length > 1)
- {
- listBox1.Items.Add(Data);
- }
- }
- listBox1.Enabled = true;
- button2.Enabled = false;
- button3.Enabled = false;
- button4.Enabled = false;
- button5.Enabled = true;
- button8.Enabled = true;
- button9.Enabled = true;
- button10.Enabled = true;
- textBox1.Enabled = false;
- textBox2.Enabled = false;
- logging = true;
- return;
- }
- MessageBox.Show("密碼錯誤或無此帳號", "登入失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- loginUser = 0;
- Initialize();
- loginUser = pos;
- button1.Text = "登入";
- listBox1.Items.Clear();
- listBox1.Enabled = false;
- button2.Enabled = true;
- button3.Enabled = true;
- button4.Enabled = true;
- button5.Enabled = false;
- button8.Enabled = false;
- button9.Enabled = false;
- button10.Enabled = false;
- textBox1.Enabled = true;
- textBox2.Enabled = true;
- textBox3.Text = null;
- logging = false;
- }
- }
- private void button2_Click(object sender, EventArgs e)//註冊
- {
- foreach (string u in user)//檢測使用者名稱是否重複或空白
- {
- if (textBox1.Text == u | textBox1.Text == "" | textBox2.Text == "")
- {
- MessageBox.Show("請檢察使用者名稱或密碼是否空白或已有相同使用者名稱", "資料錯誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else if (user.Length == 6)
- {
- MessageBox.Show("使用者已達上限", "資料錯誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- var result = MessageBox.Show("帳戶名稱:"+textBox1.Text+"\r\n帳戶是否正確?", "確認資訊", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
- if (result == DialogResult.No) { return; }//確認資訊
- savedUser += textBox1.Text + ",";
- savedPassword += textBox2.Text + ",";
- Initialize();
- creatFolder(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\topHider\" + textBox1.Text);
- MessageBox.Show("創建完成", "創建帳號", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void button3_Click(object sender, EventArgs e)//刪除
- {
- if (checkPassword() && textBox1.Text != "" && textBox2.Text != "")//檢測密碼正確
- {
- var result = MessageBox.Show("確定要刪除?","刪除帳號",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
- if (result == DialogResult.No) { return; }
- deleteAccount(loginUser);
- savedUser = savedUser.Remove(savedUser.IndexOf(user[pos]), user[pos].Length + 1);
- savedPassword = savedPassword.Remove(savedPassword.IndexOf(password[pos]),password[pos].Length+1);
- Initialize();
- DirectoryInfo diMyDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\topHider\" + textBox1.Text);
- diMyDir.Attributes = FileAttributes.Normal;
- diMyDir.MoveTo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\" + textBox1.Text);
- MessageBox.Show("刪除完成", "刪除帳號",MessageBoxButtons.OK,MessageBoxIcon.Information);
- return;
- }
- MessageBox.Show("密碼錯誤或無此帳號", "刪除失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- private void button4_Click(object sender, EventArgs e)
- {
- pos = 0;
- for (int i = 0; i < user.Length-1; i++)
- {
- deleteAccount(0);
- }
- savedPassword = "";
- savedUser = "";
- Properties.Settings.Default.user = "";
- Properties.Settings.Default.password = "";
- Properties.Settings.Default.Save();
- user = Properties.Settings.Default.user.Split(',');
- password = Properties.Settings.Default.password.Split(',');
- MessageBox.Show("資料清除完成", "刪除帳號資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void button6_Click(object sender, EventArgs e)
- {
- MessageBox.Show("目前支援使用者上限為5個\r\n目前使用者數為 : " + (user.Length - 1) + "\r\n\r\n使用者名稱必須為15字元以下\r\n密碼必須為20字元以下\r\n刪除完畢隱藏資料夾移至桌面", "說明", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void button7_Click(object sender, EventArgs e)
- {
- string msg = "";
- for(int t = 1; t < user.Length; t++)
- {
- msg += t + ". " + user[t-1] + "\r\n";
- }
- msg += "以上";
- MessageBox.Show(msg, "UserList", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //----------------
- //主程式(頁籤二)
- //----------------
- private void button8_Click(object sender, EventArgs e)
- {
- moveFolder("out");
- }
- private void button9_Click(object sender, EventArgs e)
- {
- moveFolder("in");
- }
- private void button10_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog path = new FolderBrowserDialog();
- path.ShowDialog();
- textBox3.Text = path.SelectedPath;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement