Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace 秘密檔案
  13. {
  14. public partial class Form1 : Form
  15. {
  16. //--------------
  17. //宣告全域變數
  18. //--------------
  19. string[] user ;//使用者名稱陣列
  20. string[] password;//密碼陣列
  21. string savedUser;//使用者名稱資料暫存(用於縮短程式碼
  22. string savedPassword;//密碼資料暫存(用於縮短程式碼
  23. int pos;//暫存陣列位置資訊
  24. int loginUser = 0;//登入使用者序號
  25. bool logging;//是否登入中
  26. bool initializing = true;//初次初始化
  27. //暫存各使用者資訊
  28. 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};
  29. string[] userData;//暫存登入中使用者資料
  30.  
  31. public Form1()
  32. {
  33. InitializeComponent();
  34. }
  35. //--------
  36. //初始化
  37. //--------
  38.  
  39. private void Form1_Load(object sender, EventArgs e)
  40. {
  41. textBox3.Text = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//預設目標資料夾位置
  42. creatFolder(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\topHider");//初次使用本程式,產生隱藏目標資料夾
  43. savedUser = Properties.Settings.Default.user;//帳戶資料存入暫存
  44. savedPassword = Properties.Settings.Default.password;//密碼資料存入暫存
  45. Initialize();
  46. }
  47.  
  48. public void Initialize()//初始化及儲存資料
  49. {
  50. pos = 0;//陣列位置序列號歸零
  51.  
  52. Properties.Settings.Default.slot1 = s[0];//------------------
  53. Properties.Settings.Default.slot2 = s[1];//
  54. Properties.Settings.Default.slot3 = s[2];//儲存各使用者資料
  55. Properties.Settings.Default.slot4 = s[3];//
  56. Properties.Settings.Default.slot5 = s[4];//------------------
  57.  
  58. Properties.Settings.Default.user = savedUser;//儲存帳戶資料
  59. Properties.Settings.Default.password = savedPassword;//儲存密碼資料
  60. Properties.Settings.Default.Save();//存檔
  61.  
  62. if (!initializing) { userData = s[loginUser].Split(','); }//初始化登入使用者資料
  63.  
  64. user = Properties.Settings.Default.user.Split(',');//初始化帳戶資料
  65. password = Properties.Settings.Default.password.Split(',');//初始化密碼資料
  66. initializing = false;
  67. }
  68.  
  69. //----------
  70. //Function
  71. //----------
  72.  
  73. public bool admin()
  74. {
  75. if (textBox1.Text == "admin" && textBox2.Text == "developeroptionon")
  76. {
  77. return true;
  78. }
  79. return false;
  80. }
  81.  
  82. public void creatFolder(string hidePath)//創建資料夾
  83. {
  84. Directory.CreateDirectory(hidePath);
  85. DirectoryInfo diMyDir = new DirectoryInfo(hidePath);
  86. diMyDir.Attributes = FileAttributes.Hidden;
  87. }
  88.  
  89. public void moveFolder(string io)//移動資料夾
  90. {
  91. DirectoryInfo diMyDir = new DirectoryInfo(textBox3.Text);//設定目標資料夾
  92. if (diMyDir.Exists)//資料夾是否存在
  93. {
  94. if (io == "in")
  95. {
  96. diMyDir.Attributes = FileAttributes.Hidden;
  97. diMyDir.MoveTo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\topHider\" + textBox1.Text + @"\" + diMyDir.Name);
  98. listBox1.Items.Add(diMyDir.Name);
  99. s[loginUser] += diMyDir.Name + ",";
  100. Initialize();
  101. }
  102. else
  103. if (io == "out")
  104. {
  105.  
  106. }
  107. }
  108. else
  109. {
  110. MessageBox.Show("無此資料夾", "轉移失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  111. }
  112. }
  113.  
  114. public void deleteAccount(int pos)
  115. {
  116.  
  117. for (int i = pos; i < user.Length-1; i++)
  118. {
  119. s[i] = s[i + 1];
  120. }
  121. Properties.Settings.Default.slot1 = s[0];
  122. Properties.Settings.Default.slot2 = s[1];
  123. Properties.Settings.Default.slot3 = s[2];
  124. Properties.Settings.Default.slot4 = s[3];
  125. Properties.Settings.Default.slot5 = s[4];
  126. Properties.Settings.Default.Save();
  127. }
  128.  
  129. public bool checkPassword()
  130. {
  131. for (int t = 0; t < user.Length; t++)//檢測密碼正確
  132. {
  133. if (user[t] == textBox1.Text && user.Length >1)
  134. {
  135. if (password[t] == textBox2.Text && user.Length > 1)
  136. {
  137. pos = t;
  138. loginUser = t;
  139. return true;
  140. }
  141. }
  142. }
  143. return false;
  144. }
  145.  
  146. //----------------
  147. //主程式(頁籤一)
  148. //----------------
  149.  
  150. private void button1_Click(object sender, EventArgs e)//登入
  151. {
  152. if (admin()) { button4.Visible = true; return; }
  153. if (!logging)
  154. {
  155. if (checkPassword())
  156. {
  157. loginUser = pos;
  158. Initialize();
  159. button1.Text = "登出";
  160.  
  161. foreach (string Data in userData)
  162. {
  163. if (userData.Length > 1)
  164. {
  165. listBox1.Items.Add(Data);
  166. }
  167. }
  168.  
  169. listBox1.Enabled = true;
  170. button2.Enabled = false;
  171. button3.Enabled = false;
  172. button4.Enabled = false;
  173. button5.Enabled = true;
  174. button8.Enabled = true;
  175. button9.Enabled = true;
  176. button10.Enabled = true;
  177. textBox1.Enabled = false;
  178. textBox2.Enabled = false;
  179. logging = true;
  180. return;
  181. }
  182. MessageBox.Show("密碼錯誤或無此帳號", "登入失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  183. }
  184. else
  185. {
  186. loginUser = 0;
  187. Initialize();
  188. loginUser = pos;
  189. button1.Text = "登入";
  190.  
  191. listBox1.Items.Clear();
  192. listBox1.Enabled = false;
  193.  
  194. button2.Enabled = true;
  195. button3.Enabled = true;
  196. button4.Enabled = true;
  197. button5.Enabled = false;
  198. button8.Enabled = false;
  199. button9.Enabled = false;
  200. button10.Enabled = false;
  201.  
  202. textBox1.Enabled = true;
  203. textBox2.Enabled = true;
  204. textBox3.Text = null;
  205.  
  206. logging = false;
  207. }
  208. }
  209.  
  210. private void button2_Click(object sender, EventArgs e)//註冊
  211. {
  212. foreach (string u in user)//檢測使用者名稱是否重複或空白
  213. {
  214. if (textBox1.Text == u | textBox1.Text == "" | textBox2.Text == "")
  215. {
  216. MessageBox.Show("請檢察使用者名稱或密碼是否空白或已有相同使用者名稱", "資料錯誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  217. return;
  218. }
  219. else if (user.Length == 6)
  220. {
  221. MessageBox.Show("使用者已達上限", "資料錯誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  222. return;
  223. }
  224. }
  225. var result = MessageBox.Show("帳戶名稱:"+textBox1.Text+"\r\n帳戶是否正確?", "確認資訊", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  226. if (result == DialogResult.No) { return; }//確認資訊
  227. savedUser += textBox1.Text + ",";
  228. savedPassword += textBox2.Text + ",";
  229. Initialize();
  230.  
  231. creatFolder(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\topHider\" + textBox1.Text);
  232. MessageBox.Show("創建完成", "創建帳號", MessageBoxButtons.OK, MessageBoxIcon.Information);
  233. }
  234.  
  235. private void button3_Click(object sender, EventArgs e)//刪除
  236. {
  237. if (checkPassword() && textBox1.Text != "" && textBox2.Text != "")//檢測密碼正確
  238. {
  239. var result = MessageBox.Show("確定要刪除?","刪除帳號",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
  240. if (result == DialogResult.No) { return; }
  241.  
  242. deleteAccount(loginUser);
  243. savedUser = savedUser.Remove(savedUser.IndexOf(user[pos]), user[pos].Length + 1);
  244. savedPassword = savedPassword.Remove(savedPassword.IndexOf(password[pos]),password[pos].Length+1);
  245. Initialize();
  246.  
  247. DirectoryInfo diMyDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\topHider\" + textBox1.Text);
  248. diMyDir.Attributes = FileAttributes.Normal;
  249.  
  250. diMyDir.MoveTo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\" + textBox1.Text);
  251.  
  252. MessageBox.Show("刪除完成", "刪除帳號",MessageBoxButtons.OK,MessageBoxIcon.Information);
  253. return;
  254. }
  255. MessageBox.Show("密碼錯誤或無此帳號", "刪除失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  256. }
  257.  
  258. private void button4_Click(object sender, EventArgs e)
  259. {
  260. pos = 0;
  261. for (int i = 0; i < user.Length-1; i++)
  262. {
  263. deleteAccount(0);
  264. }
  265. savedPassword = "";
  266. savedUser = "";
  267. Properties.Settings.Default.user = "";
  268. Properties.Settings.Default.password = "";
  269. Properties.Settings.Default.Save();
  270. user = Properties.Settings.Default.user.Split(',');
  271. password = Properties.Settings.Default.password.Split(',');
  272. MessageBox.Show("資料清除完成", "刪除帳號資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
  273. }
  274.  
  275. private void button6_Click(object sender, EventArgs e)
  276. {
  277. MessageBox.Show("目前支援使用者上限為5個\r\n目前使用者數為 : " + (user.Length - 1) + "\r\n\r\n使用者名稱必須為15字元以下\r\n密碼必須為20字元以下\r\n刪除完畢隱藏資料夾移至桌面", "說明", MessageBoxButtons.OK, MessageBoxIcon.Information);
  278. }
  279.  
  280. private void button7_Click(object sender, EventArgs e)
  281. {
  282. string msg = "";
  283. for(int t = 1; t < user.Length; t++)
  284. {
  285. msg += t + ". " + user[t-1] + "\r\n";
  286. }
  287. msg += "以上";
  288. MessageBox.Show(msg, "UserList", MessageBoxButtons.OK, MessageBoxIcon.Information);
  289. }
  290. //----------------
  291. //主程式(頁籤二)
  292. //----------------
  293.  
  294. private void button8_Click(object sender, EventArgs e)
  295. {
  296. moveFolder("out");
  297. }
  298.  
  299. private void button9_Click(object sender, EventArgs e)
  300. {
  301. moveFolder("in");
  302. }
  303.  
  304. private void button10_Click(object sender, EventArgs e)
  305. {
  306. FolderBrowserDialog path = new FolderBrowserDialog();
  307. path.ShowDialog();
  308. textBox3.Text = path.SelectedPath;
  309. }
  310. }
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement