Guest User

Untitled

a guest
Aug 14th, 2012
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 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.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Windows.Forms;
  10.  
  11. namespace Password_Generator
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public const int WM_NCLBUTTONDOWN = 0xA1;
  16. public const int HT_CAPTION = 0x2;
  17.  
  18. [DllImportAttribute("user32.dll")]
  19. public static extern int SendMessage(IntPtr hWnd,
  20. int Msg, int wParam, int lParam);
  21. [DllImportAttribute("user32.dll")]
  22. public static extern bool ReleaseCapture();
  23. public Form1()
  24. {
  25. InitializeComponent();
  26. }
  27. Random rand = new Random();
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. string b = "";
  31. string a = "";
  32. if (checkBox1.Checked == true)
  33. {
  34. if (!a.Contains("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
  35. a += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  36. }
  37. if(checkBox1.Checked==false)
  38. if(a.Contains("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)"))
  39. a.Replace("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ","");
  40.  
  41.  
  42. if (checkBox2.Checked == true)
  43. {
  44. if (!a.Contains("123456789"))
  45. a += "123456789";
  46. }
  47. if (checkBox2.Checked == false)
  48. if (a.Contains("123456789)"))
  49. a.Replace("123456789", "");
  50.  
  51. if (checkBox3.Checked == true)
  52. {
  53. if (!a.Contains("~!@#$%^&*()_+=-[]}{;':/.,?><"))
  54. a += "~!@#$%^&*()_+=-[]}{;':/.,?><";
  55. }
  56. if (checkBox3.Checked == false)
  57. if (a.Contains("~!@#$%^&*()_+=-[]}{;':/.,?><"))
  58. a.Replace("~!@#$%^&*()_+=-[]}{;':/.,?><", "");
  59.  
  60. if (textBox1.Text == "" || (checkBox1.Checked == false && checkBox2.Checked == false && checkBox3.Checked == false))
  61. {
  62. if (textBox1.Text == "" && (checkBox1.Checked == false && checkBox2.Checked == false && checkBox3.Checked == false))
  63. MessageBox.Show("Nu ai introdus numărul de caractere şi nu ai ales tipul caracterelor!");
  64. else
  65. {
  66. if (textBox1.Text == "")
  67. MessageBox.Show("Nu ai ales numărul de caractere!");
  68. if (checkBox1.Checked == false && checkBox2.Checked == false && checkBox3.Checked == false)
  69. MessageBox.Show("Nu ai selectat niciun fel de caracter!");
  70. }
  71.  
  72. }
  73. else
  74. {
  75. b = "";
  76. int c = Convert.ToInt32(textBox1.Text);
  77. for (int i = 1; i <= c; i++)
  78. {
  79. b += a[rand.Next(0, a.Length)];
  80.  
  81. }
  82. richTextBox1.Text = b;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. }
  91.  
  92. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  93. {
  94. if (!char.IsControl(e.KeyChar)
  95. && !char.IsDigit(e.KeyChar)
  96. && e.KeyChar != '.')
  97. {
  98. e.Handled = true;
  99. }
  100. }
  101.  
  102. private void button2_Click(object sender, EventArgs e)
  103. {
  104. if (richTextBox1.Text != "")
  105. Clipboard.SetText(richTextBox1.Text);
  106. }
  107.  
  108. private void label4_Click(object sender, EventArgs e)
  109. {
  110. Close();
  111. }
  112.  
  113. private void label4_MouseEnter(object sender, EventArgs e)
  114. {
  115. label4.BackColor = Color.White;
  116. }
  117.  
  118. private void label4_MouseLeave(object sender, EventArgs e)
  119. {
  120. label4.BackColor = Color.DarkGray;
  121. }
  122.  
  123. private void Form1_Load(object sender, EventArgs e)
  124. {
  125.  
  126. }
  127.  
  128. private void label1_MouseDown(object sender, MouseEventArgs e)
  129. {
  130. if (e.Button == MouseButtons.Left)
  131. {
  132. ReleaseCapture();
  133. SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
  134. }
  135. }
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment