/
MMDBLicense.cs
96 lines (92 loc) · 3.33 KB
/
MMDBLicense.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMDB.Core;
using System.Configuration;
using System.Deployment.Application;
using System.IO;
namespace MMDB.Core
{
public class MMDBLicense
{
string _ComputerID = "";
public string ComputerID
{
get
{
MMDBEncryption.CypherKey = "MMD8S0lution3";
return MMDBEncryption.Encrypt(_ComputerID, true);
}
set
{
MMDBEncryption.CypherKey = "MMD8S0lution3";
_ComputerID = MMDBEncryption.Decrypt(value, true);
}
}
public string FeatureName { get; set; }
const string Passcode = "MMDBSolutionsLLC3333";
public bool IsValid()
{
bool returnvalue = false;
MMDBLicenser l = new MMDBLicenser();
try
{
string LicensePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\" +
ConfigurationSettings.AppSettings["LicenseFile"].ToString();
returnvalue = l.IsValid(LicensePath, FeatureName, Passcode, false);
}
catch (Exception err)
{
MMDBLogFile.Log(err.Message);
}
return returnvalue;
}
public bool CheckDemoLicense(int days)
{
MMDB.Core.MMDBEncryption.CypherKey = Passcode;
string key = "";
key = MMDB.Core.MMDBEncryption.Encrypt("MMDB LICENSE DEMO LICENSE KEY", true);
string DemoLicense = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString().Replace(@"file:///", "").Replace(@"/", @"\")) + @"\";
if(!File.Exists(DemoLicense+@"..\Demo.key") && File.Exists(DemoLicense+@".\Scripts\Demo.key"))
{
File.Copy(DemoLicense+@".\Scripts\Demo.key", DemoLicense+@"..\Demo.key");
File.Delete(DemoLicense+@".\Scripts\Demo.key");
}
DemoLicense+=@"..\Demo.key";
if (!File.Exists(DemoLicense))
{
return false;
}
List<string> lines = new List<string>();
using (StreamReader r = new StreamReader(DemoLicense))
{
string line;
while ((line = r.ReadLine()) != null)
{
lines.Add(line);
}
}
if (MMDBEncryption.Decrypt(lines[0], true) == "MMDB LICENSE DEMO LICENSE KEY")
{
//Delete file and rewrite.
File.Delete(DemoLicense);
string[] datetime = new string[1];
datetime[0] = MMDB.Core.MMDBEncryption.Encrypt(DateTime.Now.Date.ToString(), true);
File.WriteAllLines(DemoLicense, datetime);
return true;
}
else
{
//Found file. Read it.
string startdate = MMDBEncryption.Decrypt(lines[0], true);
DateTime dt = Convert.ToDateTime(startdate).AddDays(days);
if (dt > DateTime.Now)
{
return true;
}
return false;
}
}
}
}