学习笔记:万能密码生成器,解决溢出问题
Demo http://download.csdn.net/detail/qq873113580/6373643
最近想弄个什么暴力破解的软件来玩玩,首先先把密码解决,各种长度,各种组合,全部都有
效果图

生成后 每个文件夹包含30W个密码

下面是源代码,后续会吧暴力破解软件源码贴上来,正在研究中,小白飘过,大神勿喷......
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Text.RegularExpressions;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;using System.Threading;namespace SetPassWord{ public partial class Form1 : Form { #region 全局变量 FileStream fs; StreamWriter writer; Thread t; string path = ""; int i = 0; int length = 0; string split = ""; #endregion #region 构造函数 public Form1() { InitializeComponent(); } #endregion #region 浏览按钮 private void button1_Click(object sender, EventArgs e) { if (this.fbd.ShowDialog() == DialogResult.OK) { this.txtPath.Text = this.fbd.SelectedPath; } } #endregion #region 生成按钮 private void btnSetting_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtPath.Text.Trim())) { MessageBox.Show("请填写保存地址。"); return; } if (string.IsNullOrEmpty(this.txtLength.Text.Trim())) { MessageBox.Show("请填写密码长度。"); return; } if (Convert.ToInt32(this.txtLength.Text.Trim()) < 6 || Convert.ToInt32(this.txtLength.Text.Trim()) > 30) { MessageBox.Show("密码长度长度为6-30。"); return; } if (string.IsNullOrEmpty(this.txtPassWord.Text.Trim())) { MessageBox.Show("请填写密文。"); return; } this.btnSetting.Enabled = false; this.Text = "正在生成,时间比较长,请稍后..."; this.btnSetting.Text = "生成..."; this.txtLength.Enabled = false; this.txtPassWord.Enabled = false; this.txtPath.Enabled = false; this.txtSplit.Enabled = false; this.button1.Enabled = false; path = this.txtPath.Text.Trim() + "\\" + this.txtLength.Text.Trim() + "-{0}.txt"; length = Convert.ToInt32(this.txtLength.Text); split = txtSplit.Text.Trim(); t = new Thread(new ThreadStart(Settting)); t.Start(); } #endregion #region 线程执行方法 public void Settting() { bool b = true; try { fs = new FileStream(string.Format(path, i), FileMode.CreateNew); writer = new StreamWriter(fs, Encoding.UTF8); List<char> result = GetList(this.txtPassWord.Text); int index = 0; foreach (var item in Foo(result, length)) { writer.WriteLine(item + split); index++; if (index > (i + 1) * 300000) { i++; writer.Close(); fs.Close(); fs = new FileStream(string.Format(path, i), FileMode.CreateNew); writer = new StreamWriter(fs, Encoding.UTF8); } } writer.Close(); fs.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); b = false; return; } finally { try { this.Invoke(new Action(() => this.btnSetting.Enabled = true)); this.Invoke(new Action(() => this.Text = "密码生成器")); this.Invoke(new Action(() => this.btnSetting.Text = "生成")); this.Invoke(new Action(() => this.txtLength.Enabled = true)); this.Invoke(new Action(() => this.txtPassWord.Enabled = true)); this.Invoke(new Action(() => this.txtPath.Enabled = true)); this.Invoke(new Action(() => this.txtSplit.Enabled = true)); this.Invoke(new Action(() => this.button1.Enabled = true)); } catch (Exception) { } if (b) { MessageBox.Show("生成成功。"); } } } #endregion #region 公用方法 public IEnumerable<string> Foo(List<char> metachars, int length) { if (length == 1) foreach (char x in metachars) yield return x.ToString(); else foreach (char y in metachars) foreach (string x in Foo(metachars, length - 1)) yield return y + x; } public static List<char> GetList(string strs) { List<char> list = new List<char>(); strs = strs.Trim().Replace(" ", ""); foreach (char c in strs) { list.Add(c); } list.Add(' '); return list; } #endregion #region 窗体关闭后 private void Form1_Load(object sender, EventArgs e) { this.FormClosed += Form1_FormClosed; } void Form1_FormClosed(object sender, FormClosedEventArgs e) { try { writer.Close(); fs.Close(); t.Abort(); } catch (Exception) { } } #endregion }}