From e662cac4c9c55176d954514429e8fd2f9ce1f54c Mon Sep 17 00:00:00 2001 From: "de@itstall.de" <de@itstall.de> Date: Fri, 31 Jan 2020 10:29:31 +0100 Subject: [PATCH] FrontendId in settings --- Wetterstation/Settings.Designer.cs | 1 + Wetterstation/Settings.cs | 39 ++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Wetterstation/Settings.Designer.cs b/Wetterstation/Settings.Designer.cs index fbc46c3..4e1b492 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 55c0333..048504b 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) + { + } } } -- GitLab