BomKhung.Com Đã Quay Trở Lại
Hoạt Động Dưới Tên Miền Hung.Pro.VN
00 Days
00 Hours
00 Minutes
00 Seconds
Hiện website đang cập nhật nội dung bài viết, nếu có lỗi gì mọi người có thể thông báo cho mình Tại đây!

[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

Đăng nhận xét

Đồng ý sữ dụng cookie
Chúng tôi sử dụng cookie trên trang web này để phân tích lưu lượng truy cập, ghi nhớ tùy chọn của bạn và tối ưu hóa trải nghiệm của bạn.
Xem thêm
Oops!
Có vẻ như kết nối internet của bạn có vấn đề. Vui lòng kết nối lại và duyệt web.
AdBlock Detected!
Chúng tôi phát hiện bạn đang sử dụng plugin chặn quảng cáo trong trình duyệt của mình.
Doanh thu chúng tôi kiếm được từ quảng cáo được sử dụng để quản lý trang web này, chúng tôi yêu cầu bạn đưa trang web của chúng tôi vào danh sách trắng trong plugin chặn quảng cáo của bạn.
Site is Blocked
Sorry! This site is not available in your country.
Kỹ thuật số thế hệ tiếp theo Chào mừng bạn đến với trò chuyện WhatsApp
Xin chào! Chúng tôi có thể giúp gì cho bạn hôm nay?
Nhập vào đây...