Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Interaction logic for Window3.xaml
- /// </summary>
- public partial class Window3 : Window
- {
- public Window3()
- {
- InitializeComponent();
- }
- private void btnMenu_Click(object sender, RoutedEventArgs e)
- {
- Window1 objUI = new Window1();
- objUI.Show();
- Close();
- }
- private void btnBatgen_Click(object sender, RoutedEventArgs e)
- {
- string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\FOLDERNAME";
- // 5 accounts
- string[] temp_all = new string[5];
- // define counter
- int i = 0;
- // init streamreader
- using (FileStream fs = File.OpenRead(path + "\\class1.txt"))
- using (StreamReader sr = new StreamReader(fs))
- {
- // while there are still lines of text to read, keep looping
- while (sr.EndOfStream == false)
- {
- // add line of text to the array
- temp_all[i] = sr.ReadLine();
- // increment counter
- i = i + 1;
- }
- }
- // password
- string[] wordarray = { "You", "gave", "me", "life", "now", "show", "me", "how", "to", "live" };
- // define string
- string password = "";
- // random instance
- Random rand = new Random();
- for (int i = 0; i < 2; i++)
- {
- password = password + rand.Next(0, wordarray.Length - 1);
- }
- for (int i = 0; i < temp_all.Length; i++)
- {
- string anAccount = temp_all[i];
- string[] accarr = anAccount.Split(','); // turns the string into an array of strings
- string surname = accarr[1]; // select the surname from the array
- string studentNo = accarr[4];
- // gen username Here
- //string temp_username = temp_all.
- string username = surname.Substring(0, 3); // take first threee letters of surname
- username = username + studentNo; // adds the student number to the username
- anAccount = anAccount + "," + username + "," + password;
- // save back to array
- temp_all[i] = anAccount;
- }
- // output to file
- using (FileStream fs = File.Open(path + "\\output.txt", FileMode.Append))
- using (TextWriter writer = new StreamWriter(fs))
- {
- // header
- writer.WriteLine("/*---------------------------------------------------------*/");
- writer.WriteLine(String.Format("/*Time: {0} User: {1}.*/",
- DateTime.Now, "Reece"));
- writer.WriteLine("/*---------------------------------------------------------*/");
- // now write each line
- for (int j = 0; j < temp_all.Length; j++)
- {
- writer.WriteLine(temp_alloutputArr[j]);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment