Add Crypt based password functions

This commit is contained in:
2025-01-18 21:47:49 +11:00
parent d3d7881e3b
commit 2445cac6a6
14 changed files with 180 additions and 938 deletions

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Classes\LDAP\Attribute\Password;
final class Crypt extends Base
{
public const key = 'CRYPT';
protected const subkey = 'crypt';
protected const salt = 2;
private const identifier = '';
public static function subid(string $password): bool
{
return preg_match('/^[\da-f]{2}/',self::password($password));
}
public function compare(string $source,string $compare): bool
{
return hash_equals($cp=self::password($source),crypt($compare,$cp));
}
public function encode(string $password,string $salt=NULL): string
{
if (is_null($salt))
$salt = sprintf('%s%s',self::identifier,random_salt(self::salt));
return sprintf('{%s}%s',self::key,crypt($password,$salt));
}
}