private void ConfirmBtn_Click(object sender, EventArgs e) { string adminoripsd = AdminOriPsdText.Text.Trim(); string adminnewpsd = AdminNewPsdText.Text.Trim(); string encryptornewpsd0 = EncryptorNewPsdText0.Text.Trim(); string encryptornewpsd1 = EncryptorNewPsdText1.Text.Trim(); string decryptornewpsd0 = DecryptorNewPsdText0.Text.Trim(); string decryptornewpsd1 = DecryptorNewPsdText1.Text.Trim(); string key = KeyText.Text.Trim(); bool up_admin = false, up_en0 = false, up_en1 = false, up_de0 = false, up_de1 = false, up_key = false; bool error = false; if (adminoripsd != "原密码" && adminnewpsd == "新密码") { error = true; } else if (adminoripsd == "原密码" && adminnewpsd != "新密码") { error = true; } else if (adminoripsd != "原密码" && adminnewpsd != "新密码") { if (Users.CheckPsd(adminnewpsd) > 0) { error = true; } if (!error && Users.SearchUser("admin", adminoripsd) >= 0) { up_admin = true; } else { error = true; } } if (encryptornewpsd0 != "新密码") { if (Users.CheckPsd(encryptornewpsd0) > 0) { error = true; } else { up_en0 = true; } } if (encryptornewpsd1 != "新密码") { if (Users.CheckPsd(encryptornewpsd1) > 0) { error = true; } else { up_en1 = true; } } if (decryptornewpsd0 != "新密码") { if (Users.CheckPsd(decryptornewpsd0) > 0) { error = true; } else { up_de0 = true; } } if (decryptornewpsd1 != "新密码") { if (Users.CheckPsd(decryptornewpsd1) > 0) { error = true; } else { up_de1 = true; } } if (key.Length > 0) { if (!Users.CheckKey(key)) { error = true; } else { up_key = true; } } if (error) { MessageBox.Show("设置失败!\n密码长度8-20位,支持数字、字母及!#$%^&*-_+,\n需至少包含一个数字及字母,且不能与旧密码相同。\n密钥长度32位,需为0-9及A-F。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { bool success_admin = false; bool success_en0 = false; bool success_en1 = false; bool success_de0 = false; bool success_de1 = false; bool success_key = false; string notice = ""; if (up_admin) { success_admin = Users.ChangePsd("admin", adminnewpsd, "abc"); if (success_admin) { notice += "管理员密码设置成功!\n"; } else { notice += "管理员密码设置失败!\n"; } } if (up_en0) { success_en0 = Users.ChangePsd("encrypt1", encryptornewpsd0, "abc"); if (success_en0) { notice += "用户aaa密码设置成功!\n"; } else { notice += "用户aaa密码设置失败!\n"; } } if (up_en1) { success_en1 = Users.ChangePsd("encrypt2", encryptornewpsd1, "abc"); if (success_en1) { notice += "用户bbb密码设置成功!\n"; } else { notice += "用户bbb密码设置失败!\n"; } } if (up_de0) { success_de0 = Users.ChangePsd("decrypt1", decryptornewpsd0, "abc"); if (success_de0) { notice += "用户ccc密码设置成功!\n"; } else { notice += "用户ccc密码设置失败!\n"; } } if (up_de1) { success_de1 = Users.ChangePsd("decrypt2", decryptornewpsd1, "abc"); if (success_de1) { notice += "用户ddd密码设置成功!\n"; } else { notice += "用户ddd密码设置失败!\n"; } } if (up_key) { success_key = Users.ChangeKey("admin", key, "abc"); if (success_key) { notice += "密钥设置成功!\n"; } else { notice += "密钥密码设置失败!\n"; } } if (!up_admin && !up_en0 && !up_en1 && !up_de0 && !up_de1 && !up_key) { notice += "设置失败!\n"; } notice += "\n密码设置提示:\n密码长度8-20位,支持数字、字母及!#$%^&*-_+,\n需至少包含一个数字及字母,且不能与旧密码相同。\n密钥长度32位,需为0-9及A-F。"; MessageBox.Show(notice, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); /* * if (!success) * MessageBox.Show("设置失败!\n密码长度8-20位,支持数字、字母及!#$%^&*-_+,\n需至少包含一个数字及字母,且不能与旧密码相同。\n密钥长度32位,需为0-9及A-F。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); * else if (up_admin || up_en0 || up_en1 || up_de0 || up_de1 || up_key) * MessageBox.Show("设置成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); * else * MessageBox.Show("设置失败!\n密码长度8-20位,支持数字、字母及!#$%^&*-_+,\n需至少包含一个数字及字母,且不能与旧密码相同。\n密钥长度32位,需为0-9及A-F。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); */ } ResetAdminText(); }
private void EncryptBtn_Click(object sender, EventArgs e) { List <String> sourceList = new List <string>(); String destinationText = DestinationText.Text.Trim(); if (filesAdress == null || filesAdress.Count <= 0) { MessageBox.Show("未载入文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (destinationText == null || destinationText.Equals("")) { MessageBox.Show("未设置存储地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (KeyText.Text.Trim() == null || KeyText.Text.Trim().Equals("") || KeyText.Text.Trim().Length <= 0) { MessageBox.Show("未设置加密密钥!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!Users.CheckKey(KeyText.Text.Trim())) { MessageBox.Show("加密密钥不合规范!\n密钥长度32位,需为0-9及A-F。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (destinationText.IndexOf('\\') == -1) { MessageBox.Show("敬告,解密文件地址不存在!加密失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (destinationText.IndexOf("/") != -1 || destinationText.IndexOf("?") != -1 || destinationText.IndexOf("\\\\") != -1 || destinationText.IndexOf("*") != -1 || destinationText.IndexOf("|") != -1 || destinationText.IndexOf("<") != -1 || destinationText.IndexOf(">") != -1 || destinationText.IndexOf('"') != -1) { MessageBox.Show("敬告,解密文件地址格式错误,文件名不能包含\\/?*|<>”!加密失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // 判断目标地址盘是否存在 if (!Directory.Exists(destinationText.Substring(0, destinationText.IndexOf('\\') + 1))) { MessageBox.Show("敬告,解密文件地址盘不存在!加密失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // 判断源文件地址与目标地址是否相同 for (int i = 0; i < filesAdress.Count; i++) { string tempsrc = filesAdress[i].ToString().Substring(0, filesAdress[i].ToString().LastIndexOf('\\') + 1); if (destinationText == tempsrc) { MessageBox.Show("敬告,解密文件地址与加密文件地址不能相同!加密失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } // 文件加密 for (int i = 0; i < filesAdress.Count; i++) { String sourcepath = filesAdress[i].ToString(); sourceList.Add(sourcepath); } ProcessBar processBar = new ProcessBar(sourceList, KeyText.Text.Trim(), destinationText, true); processBar.ShowDialog(); }