[C#] How to create Product Id Software in Winform

Xin chào các bạn, bài viết hôm nay mình hướng dẫn các bạn cách tạo Product Id cho phần mềm trên c# winform (XXXXX-XXXXX-XXXXX-XXXXX).

Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX

[C#] How to create Product Id Software in Winform

Trong thế giới phần mềm, "Product ID" (Product Identification) là một thuật ngữ thường được đề cập đến.

Đây là một phần quan trọng của quá trình cung cấp và quản lý phần mềm mà nhiều người dùng.

Bạn có thể sử dụng Product Id để tạo bản quyền, phân phối giống dụng...

Dưới đây, là ví dụ về một chuỗi Product Id.

Product ID là một chuỗi ký tự đặc biệt được gán cho mỗi sản phẩm phần mềm cụ thể.
Nó có thể bao gồm chữ cái, chữ số hoặc các ký tự đặc biệt. Ví dụ, "9CEC2-18FD2-71490-0CCB8-959BD" là một ví dụ về Product ID.

Trong bài viết này, mình sẽ lấy thông tin CPU-id, HDD Serial, Bios version và tên phần mềm để tạo thành một chuỗi Hash.

Chi tiết ở phần Hardware info các bạn có thể lấy thêm các thông tin tùy theo ý của bạn.
Giao diện khi các bạn chạy ứng dụng:
Và khi bạn chạy ứng dụng này ở một máy tính thì product ID này luôn cố định.

Source code C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security.Cryptography;
using System.Text;

public class HardwareInfo
{
    public string GetAppName()
    {
        return "LAPTRINHVB.NET";
    }
    public string GetCPUId()
    {
        string cpuId = string.Empty;
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT ProcessorId FROM Win32_Processor");

        foreach (ManagementObject obj in searcher.Get())
        {
            cpuId = obj["ProcessorId"].ToString();
            break;
        }

        return cpuId;
    }

    public string GetHDDSerialNumbers()
    {
        List<string> hddSerials = new List<string>();
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_DiskDrive");

        foreach (ManagementObject obj in searcher.Get())
        {
            string hddSerial = obj["SerialNumber"].ToString();
            hddSerials.Add(hddSerial);
        }

        return string.Join("_", hddSerials);
    }


    public string GetBIOSVersion()
    {
        string biosVersion = string.Empty;
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");

        foreach (ManagementObject obj in searcher.Get())
        {
            biosVersion = obj["Version"].ToString();
            break; 
        }

        return biosVersion;
    }

    public string GenerateProductID()
    {
        string appName = GetAppName();
        string cpuId = GetCPUId();
        string hddSerial = GetHDDSerialNumbers();
        string biosVersion = GetBIOSVersion();

        string combinedInfo = $"{appName}-{cpuId}-{hddSerial}-{biosVersion}";

        // Hash the combined information
        string hashedInfo = CalculateMD5Hash(combinedInfo);

        // Format the product ID
        string formattedProductID = FormatProductID(hashedInfo);

        return formattedProductID;
    }

    private string CalculateMD5Hash(string input)
    {
        using (MD5 md5 = MD5.Create())
        {
            byte[] inputBytes = Encoding.UTF8.GetBytes(input);
            byte[] hashBytes = md5.ComputeHash(inputBytes);

            StringBuilder sb = new StringBuilder();
            foreach (byte b in hashBytes)
            {
                sb.Append(b.ToString("X2"));
            }
            return sb.ToString();
        }
    }

    private string FormatProductID(string input)
    {
        string formatted = input.Substring(0, 5) + "-" + input.Substring(5, 5) + "-" + input.Substring(10, 5) + "-" + input.Substring(15, 5) + "-" + input.Substring(20, 5);
        return formatted.ToUpper();
    }
}

class Program
{
    static void Main(string[] args)
    {
        HardwareInfo hardwareInfo = new HardwareInfo();
        string productID = hardwareInfo.GenerateProductID();
        Console.WriteLine("Product ID: " + productID);

        Console.ReadLine();
    }
}

Chúc mọi người thành công với thủ thuật trên, để có thể tạo bản quyền ứng dụng thật tốt.
 

DOWNLOAD SOURCE CODE


PASSWORD UNZIP: HUNG.PRO.VN

PASSWORD UNZIP: HUNG.PRO.VN
Chúc Mọi Người Thành Công Với Thủ Thuật Trên.
Nếu mọi người có vướng mắc gì mình chia sẽ trên trang có thể gửi liên hê cho mình tại đây nhé.
Cảm ơn mọi người đã quan tâm.

No comments:

All Right Reserved © 2015 By Hung Pro VN