ramsey/uuid - 验证基于名称的散列具有我们分配给 uuid 的名称
ramsey/uuid - validate a name-based hashed has the name that we assign it to the uuid
我可以从 Packagist 下载任何可靠的 uuid 包并将其用于 Slim 框架吗?
理想情况下,我想要一个可以散列类型的 uuid,例如php,转化为字符串。然后我可以检查 uuid 是否有 'php'.
编辑:
如何验证 name-based hashed 具有我们分配给它的 uuid 的 name?
// Generate a version 3 (name-based and hashed with MD5) UUID object
$uuid3 = Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net');
$uuid = $uuid3->toString();
例如:
if ($uuid3->getName($uuid) === 'php.net') {
// do something
}
这可能吗?
最好的UUID包是https://github.com/ramsey/uuid
只需使用composer require ramsey/uuid
安装即可。
Ideally,I would an uuid that I can hash a type, e.g. php, into the string. then i can check if that uuid has 'php'.
我不明白这个。 UUID 创建一个唯一的字符串。来自 Wikipedia:
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. The term globally unique identifier (GUID) is also used.
When generated according to the standard methods, UUIDs are for practical purposes unique, without depending for their uniqueness on a central registration authority or coordination between the parties generating them
编辑。
回答你的新问题…
你不能反转哈希,所以你需要再次哈希并比较。
$uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net')->toString();
$domainFromUser = 'example.com';
$userUuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, $domainFromUser)->toString();
if ($uuid === $userUuid) {
// user provided the right domain
}
我可以从 Packagist 下载任何可靠的 uuid 包并将其用于 Slim 框架吗?
理想情况下,我想要一个可以散列类型的 uuid,例如php,转化为字符串。然后我可以检查 uuid 是否有 'php'.
编辑:
如何验证 name-based hashed 具有我们分配给它的 uuid 的 name?
// Generate a version 3 (name-based and hashed with MD5) UUID object
$uuid3 = Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net');
$uuid = $uuid3->toString();
例如:
if ($uuid3->getName($uuid) === 'php.net') {
// do something
}
这可能吗?
最好的UUID包是https://github.com/ramsey/uuid
只需使用composer require ramsey/uuid
安装即可。
Ideally,I would an uuid that I can hash a type, e.g. php, into the string. then i can check if that uuid has 'php'.
我不明白这个。 UUID 创建一个唯一的字符串。来自 Wikipedia:
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. The term globally unique identifier (GUID) is also used.
When generated according to the standard methods, UUIDs are for practical purposes unique, without depending for their uniqueness on a central registration authority or coordination between the parties generating them
编辑。
回答你的新问题…
你不能反转哈希,所以你需要再次哈希并比较。
$uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net')->toString();
$domainFromUser = 'example.com';
$userUuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, $domainFromUser)->toString();
if ($uuid === $userUuid) {
// user provided the right domain
}