看到標題不要誤會,本篇文章不是要講如何破解軟體序號。

對於想賣軟體營利的人來說,設計一個序號機制是個令人頭大的問題,剛好前陣子看到 SKGL,基本的功能它都有。像是基本的產生序號:

Generate genKey = new Generate();
genKey.secretPhase = "mypassword";  //set your password 
string sn = genKey.doKey(30);
Console.WriteLine(sn);

短短幾行,就可以產生像是MJBXY-TDTGR-KXDQN-UQQYW這樣的序號且有效日期設定為三十天後,而驗證序號的程式碼則是:

Validate validator = new Validate();
validator.secretPhase = password;
validator.Key = sn;
Console.WriteLine(validator.ExpireDate);
Console.WriteLine(validator.IsValid);

只要密碼跟產生序號時用的是同一組,驗證就會通過,而且還能檢查有效期限。

 

另外,除了有效期限,還能附加該序號所支援的 feature,例如說軟體有多個版本,那就可以指定序號是哪個版本或是該序號可以讓軟體使用哪些功能。

string password = "mypassword";
SerialKeyConfiguration config = new SerialKeyConfiguration();
config.Features = new bool[] 
{
    false, false ,false,false,
    false,true,true,false
};
Generate genKey = new Generate(config);
genKey.secretPhase = password;  //set your password
string sn = genKey.doKey(30);

Validate validator = new Validate();
validator.secretPhase = password;
validator.Key = sn;
Console.WriteLine(validator.IsValid);

foreach (bool feature in validator.Features)
{
    Console.WriteLine(feature);
}

如上述程式碼所示,設定第六、七個 feature 為 true,在驗證序號時,就可以知道哪些功能可以使用,不能使用的功能就直接隱藏。特別要注意的是,features 雖然設定八組,但驗證時會得到九組,直接略過第一組,檢查後面八組即可。

arrow
arrow
    全站熱搜

    卑微研究生 發表在 痞客邦 留言(0) 人氣()