merge([$class::id()=>$class]); } return $helpers->sort(); } /** * Given an LDAP password syntax {xxx}yyyyyy, this function will return the object for xxx * * @param string $password * @return Attribute\Password\Base|null * @throws \Exception */ public static function hash(string $password): ?Attribute\Password\Base { $m = []; preg_match('/^{([A-Z0-9]+)}(.*)$/',$password,$m); $hash = Arr::get($m,1,'*clear*'); if (($potential=static::helpers()->filter(fn($hasher)=>str_starts_with($hasher::key,$hash)))->count() > 1) { foreach ($potential as $item) { if ($item::subid($password)) return new $item; } throw new \Exception(sprintf('Couldnt figure out a password hash for %s',$password)); } elseif (! $potential->count()) { throw new \Exception(sprintf('Couldnt figure out a password hash for %s',$password)); } return new ($potential->pop()); } /** * Return the object that will process a password * * @param string $id * @return Attribute\Password\Base|null */ public static function hash_id(string $id): ?Attribute\Password\Base { return ($helpers=static::helpers())->has($id) ? new ($helpers->get($id)) : NULL; } public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { return view('components.attribute.password') ->with('o',$this) ->with('edit',$edit) ->with('old',$old) ->with('new',$new) ->with('helpers',static::helpers()->map(fn($item,$key)=>['id'=>$key,'value'=>$key])->sort()); } public function render_item_old(int $key): ?string { $pw = Arr::get($this->oldValues,$key); return $pw ? (((($x=$this->hash($pw)) && ($x::id() !== '*clear*')) ? sprintf('{%s}',$x::shortid()) : '').str_repeat('*',16)) : NULL; } public function render_item_new(int $key): ?string { $pw = Arr::get($this->values,$key); return $pw ? (((($x=$this->hash($pw)) && ($x::id() !== '*clear*')) ? sprintf('{%s}',$x::shortid()) : '').str_repeat('*',16)) : NULL; } }