diff --git a/Wetterstation/Settings.Designer.cs b/Wetterstation/Settings.Designer.cs index fbc46c3a2054bf2fabef43534f0b14c9c16da19e..4e1b4923b7a644b32e7b3777eaffe62a413cf889 100644 --- a/Wetterstation/Settings.Designer.cs +++ b/Wetterstation/Settings.Designer.cs @@ -308,6 +308,7 @@ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "Settings"; this.Text = "Settings"; + this.Load += new System.EventHandler(this.Settings_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Wetterstation/Settings.cs b/Wetterstation/Settings.cs index 55c03335a7472ba99fa5ef59dd0a5032f2e02ad2..048504bbaa602ecc7e9177606d0888e71709a914 100644 --- a/Wetterstation/Settings.cs +++ b/Wetterstation/Settings.cs @@ -8,6 +8,7 @@ using System.Management; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Security.Cryptography; namespace Wetterstation { @@ -16,7 +17,7 @@ namespace Wetterstation public Settings() { InitializeComponent(); - generateId(); + lblFrontendId.Text = "Frontend Id: " + generateId(); } private void TextBox2_TextChanged(object sender, EventArgs e) @@ -29,7 +30,10 @@ namespace Wetterstation } - private void generateId() { + private String generateId() + { + String result = "Could not found id"; + try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor"); @@ -41,11 +45,42 @@ namespace Wetterstation Console.WriteLine("Caption: {0}", queryObj["Caption"]); Console.WriteLine("Family: {0}", queryObj["Family"]); Console.WriteLine("ProcessorId: {0}", queryObj["ProcessorId"]); + Console.WriteLine("Username: {0}", Environment.UserName); + result = queryObj["ProcessorId"] + Environment.UserName; } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } + using (MD5 md5Hash = MD5.Create()) + { + return GetMd5Hash(md5Hash, result); + } + } + private string GetMd5Hash(MD5 md5Hash, string input) + { + + // Convert the input string to a byte array and compute the hash. + byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); + + // Create a new Stringbuilder to collect the bytes + // and create a string. + StringBuilder sBuilder = new StringBuilder(); + + // Loop through each byte of the hashed data + // and format each one as a hexadecimal string. + for (int i = 0; i < data.Length; i++) + { + sBuilder.Append(data[i].ToString("x2")); + } + + // Return the hexadecimal string. + return sBuilder.ToString(); + } + + private void Settings_Load(object sender, EventArgs e) + { + } } }