1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- def enroll():
-
- ## Enrolls new finger
- ##
- ## Tries to initialize the sensor
- try:
- f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
- if ( f.verifyPassword() == False ):
- raise ValueError('The given fingerprint sensor password is wrong!')
- except Exception as e:
- print('The fingerprint sensor could not be initialized!')
- print('Exception message: ' + str(e))
- exit(1)
- ## Gets some sensor information
- print('Currently stored templates: ' + str(f.getTemplateCount()))
- ## Tries to enroll new finger
- try:
- print('Waiting for finger...')
- ## Wait that finger is read
- while ( f.readImage() == False ):
- pass
- ## Converts read image to characteristics and stores it in charbuffer 1
- f.convertImage(0x01)
-
- ## Checks if finger is already enrolled
- result = f.searchTemplate()
- positionNumber = result[0]
-
- ## Gets new position number (the counting starts at 0, so we do not need to increment)
- #positionNumber = f.getTemplateCount()
-
- if ( positionNumber >= 0 ):
- f.loadTemplate(positionNumber, 0x01)
- characterics = str(f.downloadCharacteristics(0x01))
- passhashes = hashlib.sha256(characterics).hexdigest()
- passhash = passhashes[0:32]
- print('Template already exists at position #' + str(positionNumber))
- return passhash
-
- print('Remove finger...')
- time.sleep(2)
- print('Waiting for same finger again...')
- ## Wait that finger is read again
- while ( f.readImage() == False ):
- pass
- ## Converts read image to characteristics and stores it in charbuffer 2
- f.convertImage(0x02)
- ## Compares the charbuffers and creates a template
- f.createTemplate()
- ## Gets new position number (the counting starts at 0, so we do not need to increment)
- positionNumber = f.getTemplateCount()
- ## Saves template at new position number
- if ( f.storeTemplate(positionNumber) == True ):
- print('Finger enrolled successfully!')
- print('New template position #' + str(positionNumber))
- ## Hashes characteristics of template
-
- characterics = str(f.downloadCharacteristics(0x01))
- passhashes = hashlib.sha256(characterics).hexdigest()
- passhash = passhashes[0:32]
- ## Hashes characteristics of template
- print('SHA-2 hash of template: ' + passhash)
- return passhash
-
- except Exception as e:
- print('Operation failed!')
- print('Exception message: ' + str(e))
- exit(1)
- #print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest())
-
-
|