-
Notifications
You must be signed in to change notification settings - Fork 0
/
Licence.cs
143 lines (134 loc) · 3.47 KB
/
Licence.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.IO;
using System.Windows.Forms;
namespace DBTableMover
{
/// <summary>
/// Summary description for Licence.
/// </summary>
public class Licence
{
//private frmMain innerForm;
//private static int Activated;
private string outerkey;
private byte[] KEY
{
get
{
byte[] sysKey = new byte[36];
string key = "9940c1d7-ec41-455a-be84-c5eebd4d811d";
int i = 0;
foreach(char c in key.ToCharArray())
{
sysKey[i] = Convert.ToByte(c);
i++;
}
return sysKey;
}
}
private string innerkey = "c0cbe7cb-23de-4b3c-ac36-627cfd8eef24";
private byte[] CODE
{
get
{
byte[] sysCode = new byte[36];
int i = 0;
foreach(char c in innerkey.ToCharArray())
{
sysCode[i] = Convert.ToByte(c);
i++;
}
return sysCode;
}
}
/// <summary>
/// this function only tests to see if the entered strings are exactly equal to themselves.
/// only the customer's keyfile matters, the inner code it not important.
/// Other logic could include that certain customer numbers where not allowed if the
/// inner key were not equal to a certain value, functions that use the new value
/// could be included in secondary files, and calls to them could be monitored
/// </summary>
/// <returns>whether or not the licence key is valid.</returns>
public bool Valid
{
get
{
bool temp = false;
byte[] ourCode = CODE; /* Array.CreateInstance(System.Type.GetType("byte"),40);*/
byte[] theirCode = new byte[36]; /* Array.CreateInstance(System.Type.GetType("byte"),40);*/
try
{
if(outerkey.Equals(null))
{ // call frmMain.MessageBox(string inner message, Buttons, icon, title);
MessageBoxButtons buttonsOnForm = MessageBoxButtons.OK;
MessageBoxIcon iconOnForm = MessageBoxIcon.Error;
MessageBox.Show("You have not entered the KeyCode.", "Error", buttonsOnForm, iconOnForm);
}
else
{
int i = 0;
foreach(char c in outerkey.ToCharArray())
{
theirCode[i] = Convert.ToByte(c);
i++;
}
bool codeMatch = testByteArrays(ourCode, CODE);
bool keyMatch = testByteArrays(theirCode, KEY);
// two spare calls for debugging.
if(codeMatch&keyMatch)
temp = true;
}
}
catch(Exception x)
{
WriteLog("Licensing Error : " + x.Message.ToString());
}
return temp;
}
}
public Licence()
{
// have this pull the data from a registry entry or from the license file
FileInfo licFile = new FileInfo(System.AppDomain.CurrentDomain.BaseDirectory + @"\Licence.txt");
if(licFile.Exists)
{
StreamReader reader = new StreamReader(licFile.FullName);
outerkey = reader.ReadLine();
}
#if DEBUG
else
{
string licTXT = "9940c1d7-ec41-455a-be84-c5eebd4d811d";
outerkey = licTXT;
}
#endif
}
private bool testByteArrays(byte[] test1, byte[] test2)
{
int i = test1.Length;
int x = test2.Length;
if(x!=i)
return false;
else
{
x = 0;
foreach(byte b in test1)
{
byte testByte = test2[x];
if(testByte!=b)
return false;
x++;
}
return true;
}
}
/// <summary>
/// this is an internal function to write debug information to a textfile
/// </summary>
/// <param name="message">the message to send to the log</param>
private void WriteLog(string message)
{
ProjectMethods.WriteLog("Licence", message);
}
}
}