Skip to content

Commit db4ec18

Browse files
committed
v0.4.1 - machine ID generation
1 parent 67cd65d commit db4ec18

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.4.1
4+
5+
* added two functions to generate a machine ID for the PHP instance. `Key::getMachineId` returns a hash of the machine ID, whereas `Key::getMachineIdPlain` returns the machine ID in readable format, not hashed. Read the function documentation for information of this hash being calculated.
6+
37
## v0.4
48

59
* outsourced helper function into the `Helper.cryptolens.php` class

classes/Key.cryptolens.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ public function __construct($cryptolens){
1111
$this->group = Cryptolens::CRYPTOLENS_KEY;
1212
}
1313

14+
/**
15+
* getMachineId() - Generates a machine ID based on the server's OS, OS version, hostname, architecture, total disk space, unix timestamp of creation of root file system and php's currently installed version
16+
*
17+
* The hash generated strips out any white spaces and commas and replaces them with two underlines "__"
18+
* The possibility of this method being completely unique is not given, as a update of the php version results in the hash getting invalid.
19+
* The function `getMachineIdPlain` allows you to retrieve an JSON to cache this value to generate the hash later on again for comparison.
20+
*/
21+
public static function getMachineId(){
22+
$fingerprint = [php_uname(), disk_total_space("."), filectime("/"), phpversion()];
23+
return hash("sha256", json_encode($fingerprint));
24+
}
25+
26+
public static function getMachineIdPlain(){
27+
$fingerprint = [php_uname(), disk_total_space("."), filectime("/"), phpversion()];
28+
foreach($fingerprint as $key => $value){
29+
$fingerprint[$key] = str_replace([" ", ",", "\n", "\r", "\t", "\v", "\x00"], "__", $fingerprint[$key]);
30+
}
31+
$fingerprint = implode("__", $fingerprint);
32+
$fingerprint = json_encode($fingerprint);
33+
34+
return $fingerprint;
35+
}
36+
1437

1538
/**
1639
* activate() - Activates a Key

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "Manage your licenses with this Cryptolens API client",
44
"type": "library",
55
"license": "MIT",
6+
"version": "0.4.1",
67
"authors": [
78
{
89
"name": "Ente",

0 commit comments

Comments
 (0)