Guest User

Untitled

a guest
Apr 18th, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1.  
  2. /// <summary>
  3. /// Interaction logic for Window3.xaml
  4. /// </summary>
  5. public partial class Window3 : Window
  6. {
  7. public Window3()
  8. {
  9. InitializeComponent();
  10. }
  11.  
  12. private void btnMenu_Click(object sender, RoutedEventArgs e)
  13. {
  14. Window1 objUI = new Window1();
  15. objUI.Show();
  16. Close();
  17. }
  18.  
  19. private void btnBatgen_Click(object sender, RoutedEventArgs e)
  20. {
  21. string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\FOLDERNAME";
  22.  
  23. // 5 accounts
  24.  
  25. string[] temp_all = new string[5];
  26.  
  27. // define counter
  28.  
  29. int i = 0;
  30.  
  31. // init streamreader
  32.  
  33. using (FileStream fs = File.OpenRead(path + "\\class1.txt"))
  34. using (StreamReader sr = new StreamReader(fs))
  35. {
  36. // while there are still lines of text to read, keep looping
  37.  
  38. while (sr.EndOfStream == false)
  39. {
  40. // add line of text to the array
  41.  
  42. temp_all[i] = sr.ReadLine();
  43.  
  44. // increment counter
  45.  
  46. i = i + 1;
  47. }
  48. }
  49.  
  50.  
  51.  
  52. // password
  53.  
  54. string[] wordarray = { "You", "gave", "me", "life", "now", "show", "me", "how", "to", "live" };
  55.  
  56. // define string
  57.  
  58. string password = "";
  59.  
  60. // random instance
  61.  
  62. Random rand = new Random();
  63.  
  64. for (int i = 0; i < 2; i++)
  65. {
  66. password = password + rand.Next(0, wordarray.Length - 1);
  67. }
  68.  
  69. for (int i = 0; i < temp_all.Length; i++)
  70. {
  71. string anAccount = temp_all[i];
  72.  
  73. string[] accarr = anAccount.Split(','); // turns the string into an array of strings
  74.  
  75. string surname = accarr[1]; // select the surname from the array
  76.  
  77. string studentNo = accarr[4];
  78.  
  79. // gen username Here
  80.  
  81. //string temp_username = temp_all.
  82.  
  83. string username = surname.Substring(0, 3); // take first threee letters of surname
  84.  
  85. username = username + studentNo; // adds the student number to the username
  86.  
  87. anAccount = anAccount + "," + username + "," + password;
  88.  
  89. // save back to array
  90.  
  91. temp_all[i] = anAccount;
  92. }
  93.  
  94. // output to file
  95.  
  96. using (FileStream fs = File.Open(path + "\\output.txt", FileMode.Append))
  97. using (TextWriter writer = new StreamWriter(fs))
  98. {
  99. // header
  100.  
  101. writer.WriteLine("/*---------------------------------------------------------*/");
  102. writer.WriteLine(String.Format("/*Time: {0} User: {1}.*/",
  103. DateTime.Now, "Reece"));
  104. writer.WriteLine("/*---------------------------------------------------------*/");
  105.  
  106. // now write each line
  107.  
  108. for (int j = 0; j < temp_all.Length; j++)
  109. {
  110. writer.WriteLine(temp_alloutputArr[j]);
  111. }
  112.  
  113. }
  114. }
  115. }
  116. }
Add Comment
Please, Sign In to add comment