通过程序来生成密码本--加强密码的难度
static void Main(string[] args)
{
// 定义生成密码的数量
int count = 100;
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
// 生成随机密码集合
var passwords = GeneratePasswords(count);
// 导出到 Excel 文件
ExportToExcel(passwords);
}
static string[] GeneratePasswords(int count)
{
// 定义密码长度和字符集
int length = 8;
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
// 生成随机密码集合
var random = new Random();
var passwords = new string[count];
for (int i = 0; i < count; i++)
{
var password = new char[length];
for (int j = 0; j < length; j++)
{
password[j] = chars[random.Next(chars.Length)];
}
passwords[i] = new string(password);
}
return passwords;
}
static void ExportToExcel(string[] passwords)
{
// 创建 Excel 文件
var fileInfo = new FileInfo("passwords.xlsx");
using (var package = new ExcelPackage(fileInfo))
{
// 添加工作表
var worksheet = package.Workbook.Worksheets.Add("Passwords");
// 添加表头
worksheet.Cells[1, 1].Value = "Password";
// 添加数据
for (int i = 0; i < passwords.Length; i++)
{
worksheet.Cells[i + 2, 1].Value = passwords[i];
}
// 保存文件
package.Save();
}
}





赞









