liscence.cs

mail@pastecode.io avatar
unknown
actionscript
2 years ago
3.2 kB
1
Indexable
Never
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Data.SqlClient;
using System.Net.NetworkInformation;

namespace Scoot.Forms
{
    public partial class liscence : MetroFramework.Forms.MetroForm
    {
        public liscence()
        {
            InitializeComponent();
        }

        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=scoot;Integrated Security=True;");
        SqlCommand cmd;

        private void liscence_Load(object sender, EventArgs e)
        {

        }

        private void addbtn_Click(object sender, EventArgs e)
        {
            string hash = "H@N/#T$";

            try
            {
                byte[] data = Convert.FromBase64String(key.Text);
                using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
                {
                    byte[] keys = md5.ComputeHash(UTF8Encoding.UTF7.GetBytes(hash));
                    using (TripleDESCryptoServiceProvider tripdes = new TripleDESCryptoServiceProvider() { Key = keys, Mode = CipherMode.ECB, Padding = PaddingMode.ISO10126 })
                    {

                        ICryptoTransform transform = tripdes.CreateDecryptor();
                        byte[] result = transform.TransformFinalBlock(data, 0, data.Length);
                        string a = UTF8Encoding.UTF8.GetString(result);

                        var macAddr =
                                (
                                    from nic in NetworkInterface.GetAllNetworkInterfaces()
                                    where nic.OperationalStatus == OperationalStatus.Up
                                    select nic.GetPhysicalAddress().ToString()
                                ).FirstOrDefault();

                        if (a == macAddr)
                        {
                            cmd = new SqlCommand(@"INSERT INTO [dbo].[liscence]
                                                               ([key])
                                                         VALUES('" + a + "')", cn);
                            cn.Open();
                            cmd.ExecuteNonQuery();
                            cn.Close();
                            MessageBox.Show("تمت عملية التفعيل بنجاح", "رسالة", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            dashboard d = new dashboard();
                            d.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show("مفتاح التفعيل الذي قمت بإذخاله خاظئ", "رسالة", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("مفتاح التفعيل الذي قمت بإذخاله خاظئ", "رسالة", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            
        }
    }
}