Secondary development of fingerprint sensor in Delphi
1. Introduction to fingerprint sensor
Fingerprints have the reputation of "the first of physical evidence". The scientific community’s conclusion on fingerprints is: Assuming there are 5 billion people on the earth, it will take 300 years for two identical fingerprints to appear. It can be seen that the uniqueness of fingerprints has an irrefutable status.
Fingerprint sensors transformed digital security systems as we know them for the first time. Previously, everything relied on passwords. You must use your own username and configure your system. You must cover your keyboard so others cannot see your password. However, if you are not careful, it is easy for anyone to steal your password.
Relevant experts predict: "Through the fingerprint recognition system, we have expanded the security needs of home and business computer users. In the near future, whether it is on the local area network or the Internet, whether it is registering or accessing security data, it will be impossible to No more passwords are needed, all it takes is a touch of your finger."
2. Introduction to the secondary development of fingerprint scanner
Currently, there are many fingerprint scanner manufacturers in the world, with great influence. The U.are.U series of DigitalPersona is the most widely used one. DigitalPersona is the world's largest computer keyboard manufacturer. This company uses bioengineering security systems. Already included in a deal with Chicony Electronics to integrate DigitalPersona's U.are.U fingerprint-sensing security system into keyboards made for HP, Compaq and IBM, among others.
The secondary development of the fingerprint sensor introduced in this article is based on DigitalPersona's U.are.U 2000. U.are.U is the abbreviation of you are you (you are you). U.are.U 2000 Micro Fingerprint Collection The device can automatically read fingerprint images and transmit the digital fingerprint images to the computer through the USB interface. It is an ideal accessory for laptops, desktops or other PC devices that require authentication.
U.are.U 2000 is a low-cost, compact fingerprint reader. It integrates a precision optical system, LED light source and CMOS camera to work together to perform voltage control and automatic correction during image capture, and uses a plug-and-play USB interface. U.are.U 2000 fingerprint scanning and collection is designed to lead to DigitalPersona U.are.U Fingerprint recognition algorithms, applications, and interfaces to the DigitalPersona Universal Authentication Manager (UAM) - these fingerprint-related applications include Windows Login, screen lock, password replacement and encrypted disk drive.
When purchasing fingerprint sensor hardware products, merchants usually include hardware drivers, product manuals, secondary development kits and development program examples. Through the software development kit (SDK), the fingerprint recognition function can be added to the application.
3. Key technologies in the secondary development process of fingerprint scanners
1.dll call
First, let’s introduce the method of calling the dll in the fingerprint sensor development kit in delpi. Place the uruShell.dll in the development package in the program directory or System directory. For the sake of clarity, the DLL call statements are concentrated in a program unit Shelluru.pas, in which the functions of uruShell.dll are exported and related reference statements are made. The specific source code is as follows:
unit Shelluru;
interface
uses windows, Messages;
const
FT_OK = 0; // Success
FT_ERR_NO_INIT = -1; // No initialization
FT_ERR_UNKNOWN_DEVICE = -10; // Unknown device
FT_ERR_DEVICE_CONNECTED = -18; // The device is connected
FT_ERR_NO_DEVICE_CONNECTED = -19; // No device can be connected
MAX_REGISTER_COUNT= 8; // Maximum number of registers
ERR_REGISTER_FAIL= -110; // Registration failed
ERR_VERIFY_FAIL= -111; // Verification failed
ERR_REGISTER_COUNT= -112; // Number of registrations
{The following is a custom message, MSG_FINGER_CAPTURED fingerprint acquisition message; }MSG_WAITING_FOR_IMAGE fingerprint waiting message.
MSG_FINGER_CAPTURED= WM_USER + 80;
MSG_WAITING_FOR_IMAGE= WM_USER + 81;
type
PRegisterPixels = ^TRegisterPixels;
TRegisterPixels = array[1..MAX_REGISTER_COUNT] of Pointer;
///uru_Init initializes the fingerprint sensor. Parameters: numOfDev returns the number of fingerprint sensors connected to the computer; FeatureLen returns the fingerprint data length.
function uru_Init(var numOfDev, FeatureLen: integer): integer; stdcall;
///uru_Connect connects to a specific fingerprint sensor. Parameter: DeviceNo fingerprint sensor number.
function uru_Connect(DeviceNo: integer): integer; stdcall;
///uru_Terminate disconnects from the fingerprint sensor. Parameter: DeviceNo fingerprint sensor number.
procedure uru_Terminate(DeviceNo: integer); stdcall;
///uru_AllocFeature assigns fingerprint data address. Parameters: Address pointer returned by Feature.
procedure uru_AllocFeature(var Feature: pointer); stdcall;
///uru_FreeFeature releases the allocated address. Parameters: Address pointer returned by Feature.
procedure uru_FreeFeature(var Feature: pointer); stdcall;
///uru_GetImageWidth gets the fingerprint image width.
function uru_GetImageWidth: integer; stdcall;
///uru_GetImageHeight gets the fingerprint image height.
function uru_GetImageHeight: integer; stdcall;
///uru_Register fingerprint registration function. Parameters: hwnd window handle, used for message transmission; DevieceNo fingerprint sensor number;
///fngCount fingerprint registration times; Pixels fingerprint image connection pointer; Features fingerprint registration data pointer.
function uru_Register(hwnd: HWND; DeviceNo, fngCount: integer;Pixels: PRegisterPixels; Features: pointer): integer; stdcall;
///uru_AcquireFeatures fingerprint verification function. Parameters: hwnd window handle, used for message transmission; DevieceNo fingerprint sensor number.
function uru_AcquireFeatures(hwnd: HWND; DeviceNo: integer; Pixels, Features: pointer): integer; stdcall;
///uru_verifyFeatures fingerprint comparison function. Parameters: srcFeatures needs to compare fingerprint data; dstFeatures needs to compare fingerprint data.
function uru_verifyFeatures(srcFeatures, dstFeatures: pointer): Boolean; stdcall;
///dll registration function
procedure uru_DllRegister; stdcall;
///Interrupt the specific fingerprint sensor imaging function. Parameter: DeviceNo fingerprint sensor number.
Procedure uru_StopGetImage(DeviceNO:Integer);Stdcall;
implementation
const
DLLNAME= 'uruShell.dll';
{The following is the declaration of calling the exported function of uruShell.dll}
function uru_Init; external DLLNAME;
function uru_Connect; external DLLNAME;
procedure uru_Terminate; external DLLNAME;
procedure uru_AllocFeature; external DLLNAME;
procedure uru_FreeFeature; external DLLNAME;
function uru_GetImageWidth; external DLLNAME;
function uru_GetImageHeight; external DLLNAME;
function uru_Register; external DLLNAME;
function uru_AcquireFeatures; external DLLNAME;
function uru_verifyFeatures; external DLLNAME;
procedure uru_DllRegister; external DLLNAME;
Procedure uru_StopGetImage;external DLLNAME;
end.
After completing the above work, you can reference the Shelluru.pas file in the main project file, and then call the functions defined in the Shelluru.pas file.
2. Save the verified fingerprint data in a file or database
By calling the functions defined above, we can implement a fingerprint identification system for fingerprint registration, verification, fingerprint data storage, and fingerprint re-verification (recognition). The following focuses on the programming implementation of the fingerprint registration and verification identification process:
procedure TForm1.BtnRegisterClick(Sender: TObject); file://Register fingerprint
var
i:integer;
begin
if UserList.Selected = nil then
begin
MessageBox(application.Handle, 'Please select a user first!', nil, MB_OK);
Exit;
end;
if UserList.Selected.Data <> nil then
Feature := UserList.Selected.Data file://Feature is empty at this time
else
uru_AllocFeature(Feature);
if Feature = nil then file://If the fingerprint feature is empty
begin
Status.SimpleText := 'Cannot allocate Feature memory';
Exit;
end;
for i := 1 to 4 do
begin
FillChar(Pixels[i]^, uru_GetImageWidth * uru_GetImageHeight, $FF);
Images[i].Refresh;
end;
Status.SimpleText := 'Start registration' + UserList.Selected.Caption + 'Fingerprint...';
if uru_Register(Handle, DeviceNo, 4, @Pixels, Feature) = FT_OK then
begin
Status.SimpleText := UserList.Selected.Caption + ': Registration successful!';
if UserList.Selected.Data = nil then
UserList.Selected.Data := Feature;
end
else
begin
if UserList.Selected.Data = nil then uru_FreeFeature(Feature);
Status.SimpleText := UserList.Selected.Caption + ': Registration failed!';
end;
end;
This function mainly calls the uru_Register function in the DLL to register fingerprints for users. Registering fingerprints is to extract the characteristic value of the fingerprint, allocate a memory for the characteristic value to store the fingerprint characteristic value data, and use a pointer to point to this memory , so that it can be retrieved in the future. After registration is completed, a verification must be performed immediately to ensure that the data is correct. The verification process is as follows:
procedure TForm1.BtnVerifyClick(Sender: TObject); file://verification fingerprint
var
aFeature:pointer;
i: integer;
fingerpath: string;
begin
fingerpath:='C:/finger'+Edit9.Text+Edit10.Text;//Fingerprint data storage path
if UserList.Selected = nil then
begin
MessageBox(Application.Handle, 'Please select a user first!', nil, MB_OK);
Exit;
end;
if UserList.Selected.Data = nil then
begin
MessageBox(Application.Handle, PChar(Format('User %s has not registered fingerprint yet, please register first!', [UserList.Selected.Caption])), nil, MB_OK);
Exit;
end;
FillChar(Pixels[5]^, uru_GetImageWidth * uru_GetImageHeight, $FF);
Images[5].Refresh;
Status.SimpleText := 'Start verification' + UserList.Selected.Caption + 'Fingerprint...';
Feature := UserList.Selected.Data; file://Fingerprint data needs to be compared
move(Feature^,byt,len); file://Move a segment in memory with a length of len, and move the data starting from Feature to the byte array
uru_AllocFeature(aFeature);//Assign fingerprint data address
if (uru_AcquireFeatures(handle, DeviceNo, Pixels[5], aFeature) = FT_OK) and uru_verifyFeatures(@byt, aFeature) then
file://uru_AcquireFeaturesFingerprint Verification
file://uru_verifyFeaturesFingerprint comparison
begin
Status.SimpleText := UserList.Selected.Caption + ': Verification successful!';
AssignFile(F,fingerpath);//Assign file
ReWrite(F);//Rewrite the file
for i:=0 to len do
Write(F,byt[i]);//Write fingerprint sensor data to file
CloseFile(F);//Close the file
end
else
Status.SimpleText := UserList.Selected.Caption + ': Verification failed!';
uru_FreeFeature(aFeature); file://release memory
end;
The key to the above process is to promptly save the fingerprint data in the memory into a data file after the fingerprint verification is successful. The data file name is preferably the user name plus a number, so that the corresponding user fingerprint data can be easily found during subsequent verification. Finally, remember to release the temporarily allocated memory. Store the fingerprint data in a file. You can then open the file to retrieve the data file and perform a matching process with the current user to verify the correct identity of the user. The specific process is as follows:
procedure TForm1.BitBtn2Click(Sender: TObject); file://Verify old user fingerprint
var
aFeature1: pointer;
i: integer;
begin
if OpenDialog1.Execute then
begin
AssignFile(G,OpenDialog1.FileName);//Specify file
Reset(G);//Reset file
for i:=0 to len do
Read(G, byt2[i]);//Move the fingerprint sensor data in the file to the byte2 array
CloseFile(G);//Close the file
end;
FillChar(Pixels[5]^, uru_GetImageWidth * uru_GetImageHeight, $FF);
Images[5].Refresh;
Status.SimpleText := 'Start verification' + UserList.Selected.Caption + 'Fingerprint...';
uru_AllocFeature(aFeature1);//Assign fingerprint data address
if (uru_AcquireFeatures(handle, DeviceNo, Pixels[5], aFeature1) = FT_OK) and uru_verifyFeatures(@byt2, aFeature1) then
Status.SimpleText := UserList.Selected.Caption + ': Verification successful!'
else
Status.SimpleText := UserList.Selected.Caption + ': Verification failed!';
uru_FreeFeature(aFeature1); file://release memory
end;
In fact, fingerprint data can also be stored in a database, so that a multi-layer structure system can be implemented. Fingerprint data is centrally accessed in the database on the server. The client uploads the registration data to the server as needed, or reads it from the server when old users need to be verified. Data, ensuring security.
4. Summary
This article introduces the use of U.are.U 2000 The development kit of the fingerprint sensor is developed for secondary development to implement a process of fingerprint data registration, verification, data storage and old fingerprint re-verification. This process can be used in some systems that need to identify personal identities through fingerprints. The author developed it on this basis. A prototype of a temporary residence permit management system for public security agencies or residential communities was developed, which mainly implements the The temporary residence permit management function of the household. This article only introduces the method of calling the DLL in the fingerprint sensor development package and the key processes of registration and verification in secondary development. As for the connection, initialization, and display of fingerprint images of the fingerprint device, because It is relatively simple, so there is no in-depth discussion. Readers can develop it themselves based on the functions provided by the dll. Welcome to write to me to discuss, my email is [email protected]