kamshory / ZKLibrary

ZKLibrary is PHP library for reading and writing data to attendance device using UDP protocol. This library useful to comunicate between web server and attendance device directly without addition program. This library is implemented in the form of class. So that you can create an object and use it functions.
GNU General Public License v2.0
194 stars 176 forks source link

Getting And setting user templates. #79

Open AmirTallap opened 4 years ago

AmirTallap commented 4 years ago

Well, I know that there are no proper solution to get or set the fingerprint template from the device.

But from what I understand from this library, is that it uses an algorithm to store it on the device. Here is the catch, the algorithm is an encoded string. The machine does that. So, using "unpack" to get the vx10 algorithm template string is the proper way to restore it later.

Are there any ideas or anyone who can think of a solution? I'm sure it can be done. The packet response from the machine is binary, afaik.

`

public function getUserTemplate($uid, $finger) { $template_data = ''; $this->user_data = array(); $command = CMD_USERTEMP_RRQ; $byte1 = chr((int)($uid % 256)); $byte2 = chr((int)($uid >> 8)); $command_string = $byte1.$byte2.chr($finger); $chksum = 0; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr( $this->received_data, $this->start_data, 8) ); $reply_id = hexdec( $u['h8'].$u['h7'] ); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); try { $this->received_data = $this->recv(); $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr( $this->received_data, $this->start_data, 8 ) ); $bytes = $this->getSizeTemplate(); if($bytes) { while($bytes > 0) { $received_data = $this->recv(1032); array_push( $this->user_data, $received_data); $bytes -= 1024; } $this->session_id = hexdec( $u['h6'].$u['h5'] ); $received_data = $this->recv(); } $template_data = array(); if(count($this->user_data) > 0) { for($x=0; $x<count($this->user_data); $x++) { if ($x == 0) { $this->user_data[$x] = substr($this->user_data[$x], 8); } else { $this->user_data[$x] = substr($this->user_data[$x], 8); } } $user_data = implode('', $this->user_data); $template_size = strlen($user_data)+6; $prefix = chr($template_size%256).chr(round($template_size/256)).$byte1.$byte2.chr($finger).chr(1); $user_data = $prefix.$user_data; if(strlen($user_data) > 6) { $valid = 1; $template_data = array($template_size, $uid, $finger, $valid, $user_data); } } return $template_data; } catch(ErrorException $e) { return FALSE; } catch(exception $e) { return FALSE; } }

`

I'm sure there is a way to get that algorithm string. And restore it in the following function

`

public function setUserTemplate($data) { $command = CMD_USERTEMP_WRQ; $command_string = $data; //$length = ord(substr($command_string, 0, 1)) + ord(substr($command_string, 1, 1))256; return $this->execCommand($command, $command_string); / $chksum = 0; $session_id = $this->session_id; $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6/H2h7/H2h8', substr( $this->received_data, $this->start_data, 8) ); $reply_id = hexdec( $u['h8'].$u['h7'] ); $buf = $this->createHeader($command, $chksum, $session_id, $reply_id, $command_string); $this->send($buf); try { $u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr( $this->received_data, $this->start_data, 8 ) ); $this->session_id = hexdec( $u['h6'].$u['h5'] ); return substr( $this->received_data, 8 ); } catch(ErrorException $e) { return FALSE; } catch(exception $e) { return FALSE; } */ }

`

Any ideas might make it work.

johnebarita commented 4 years ago

Hi there I am also working on an attendance system using a fingerprint scanner. I figured you might give some tips on where I can start. It for our capstone project actually. I hope you can reply to this message. I badly need some help. Thank you.