High School Project

Welcome to the “Future Innovators: Cool STEM Projects to Change the World” series! In this project, you will learn how to create a Biometric Authentication App that uses biometric data—like fingerprints, face recognition, or voice—to verify users’ identities. Biometric authentication is commonly used for securing devices, online accounts, and personal information, making it an essential technology in modern digital security.

By the end of this project, you’ll have a working biometric login system that allows users to authenticate using their voice or face. This project will introduce you to basic security concepts and how modern apps use biometrics to enhance security.


What You Will Learn

  • How biometric authentication works, including fingerprints, voice recognition, and facial recognition.
  • How to use programming languages like Python or JavaScript to create a secure login system.
  • How to integrate biometric sensors like microphones or webcams to capture and verify biometric data.
  • The importance of digital security and how biometrics can make systems safer and more user-friendly.

STEM Learning Process

1. Science: Explore how biometric data (fingerprints, voice, or face) is unique to each person and can be used for secure authentication.
2. Technology: Learn how to build and integrate biometric authentication systems into apps using programming tools.
3. Engineering: Design a secure, reliable biometric login system that can verify a user’s identity through different data points.
4. Math: Understand the algorithms behind biometric matching and the probability of false positives or false negatives.


What You Need

Software Requirements:

  • A computer with a webcam or microphone for capturing biometric data.
  • Python with libraries like OpenCV (for face recognition) and SpeechRecognition (for voice authentication).
  • Flask (optional) if you want to build a web-based authentication app.

Biometric Libraries:


What is Biometric Authentication?

Biometric authentication uses biological traits like fingerprints, face structure, or voice patterns to verify a person’s identity. Since these traits are unique to each individual, biometric systems provide an extra layer of security, making it much harder for hackers to break into systems. In this project, we’ll focus on two types of biometric authentication: face recognition and voice authentication.


Step-by-Step Guide to Building a Biometric Authentication App

Step 1: Set Up Your Development Environment

To get started, you’ll need a development environment where you can write and test your code. Here’s how to set it up:

  1. Install Python:
  • Download and install Python from the official website: Python.org
  1. Install Required Libraries:
  • Use pip to install the necessary libraries. Open your terminal and run the following commands:
    • pip install opencv-python (for face recognition)
    • pip install SpeechRecognition (for voice authentication)
    • pip install Flask (optional, for creating a web app)

Step 2: Building the Face Recognition System

We’ll begin by implementing facial recognition to authenticate users. The program will use the computer’s webcam to capture an image of the user’s face, compare it to a stored face, and authenticate the user if there’s a match.

Step 2.1: Capture a User’s Face

Start by writing a Python script that captures an image of the user’s face from the webcam.

Python
import cv2

# Initialize the webcam
cam = cv2.VideoCapture(0)

# Load OpenCV's pre-trained face detector
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

# Capture image
ret, frame = cam.read()

# Convert the image to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Detect face in the image
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)

# Draw a rectangle around the face
for (x, y, w, h) in faces:
    cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)

# Show the image with the detected face
cv2.imshow('Face', frame)

# Save the image
cv2.imwrite('captured_face.jpg', frame)

# Release the camera and close windows
cam.release()
cv2.destroyAllWindows()

This code captures an image from the webcam, detects the user’s face, draws a rectangle around it, and saves the image.

Step 2.2: Face Recognition Using OpenCV

Now that we can capture a user’s face, let’s compare it to a stored face for authentication.

Python
import cv2
import numpy as np

# Load the stored face image and the captured face
stored_face = cv2.imread('stored_face.jpg', 0)
captured_face = cv2.imread('captured_face.jpg', 0)

# Resize images to the same size
stored_face = cv2.resize(stored_face, (200, 200))
captured_face = cv2.resize(captured_face, (200, 200))

# Compute the difference between the two faces
difference = cv2.absdiff(stored_face, captured_face)

# Calculate the percentage of similarity
similarity = 100 - (np.sum(difference) / (200 * 200)) * 100

# Print the result
if similarity > 90:
    print("Authentication Successful!")
else:
    print("Authentication Failed!")

This script compares the stored face to the newly captured face, calculating how similar they are and printing whether the user is authenticated.


Step 3: Building the Voice Authentication System

Next, we’ll implement voice authentication using the SpeechRecognition library. This system will record the user’s voice and compare it to a stored voice sample.

Step 3.1: Capture and Store a User’s Voice

First, let’s write code that records the user’s voice and saves it as a .wav file.

Python
import speech_recognition as sr

# Initialize recognizer
recognizer = sr.Recognizer()

# Capture the user's voice
with sr.Microphone() as source:
    print("Please say something...")
    audio = recognizer.listen(source)

# Save the audio to a file
with open("captured_voice.wav", "wb") as f:
    f.write(audio.get_wav_data())

This code listens for the user’s voice and saves the recording as captured_voice.wav.

Step 3.2: Compare the Recorded Voice to the Stored Voice

Now let’s compare the recorded voice with a stored voice sample to authenticate the user.

Python
import speech_recognition as sr
from scipy.io import wavfile
import numpy as np

# Load stored voice sample and captured voice
stored_rate, stored_voice = wavfile.read('stored_voice.wav')
captured_rate, captured_voice = wavfile.read('captured_voice.wav')

# Calculate the difference between the two voice samples
if len(stored_voice) > len(captured_voice):
    stored_voice = stored_voice[:len(captured_voice)]
else:
    captured_voice = captured_voice[:len(stored_voice)]

# Compute the similarity between the two voices
difference = np.abs(stored_voice - captured_voice)
similarity = 100 - (np.sum(difference) / len(difference))

# Print the result
if similarity > 80:  # Set threshold for similarity
    print("Authentication Successful!")
else:
    print("Authentication Failed!")

This script compares the recorded voice to a stored voice sample and determines whether the user is authenticated based on similarity.


Step 4: Optional – Creating a Web-Based Authentication App

If you want to build a web-based version of the Biometric Authentication App, you can use Flask to create a simple web interface.

Step 4.1: Set Up Flask

  1. Install Flask:
Python
   pip install Flask
  1. Create a basic Flask app:
Python
from flask import Flask, render_template, request
import cv2
import speech_recognition as sr

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/authenticate', methods=['POST'])
def authenticate():
    if request.form['method'] == 'face':
        # Call the face recognition function
        pass  # Add face recognition logic here
    elif request.form['method'] == 'voice':
        # Call the voice recognition function
        pass  # Add voice recognition logic here
    return "Authentication Complete"

if __name__ == '__main__':
    app.run(debug=True)

This code sets up a basic web interface where users can choose between face recognition or voice authentication.


Step 5: Testing Your Biometric Authentication App

Face Recognition:

– Run the face recognition script and have your computer capture and authenticate your face.

Test with a different face to ensure the system only allows authorized users.

Voice Authentication:

  • Run the voice authentication script and speak into the microphone.
  • Compare the recorded voice to the stored voice and check if the authentication works properly.

Customizing Your Biometric Authentication App

Here are some ways to enhance your project:

1. Add Fingerprint Authentication:

  • If your device supports fingerprint readers, you can integrate it into the app as another form of biometric authentication.

2. Implement Multi-Factor Authentication (MFA):

  • Add a second layer of security by requiring users to authenticate with both face and voice.

3. Create a User Database:

  • Store multiple users’ biometric data and create a system that supports different user accounts.

What’s Next?

Congratulations! You’ve built a Biometric Authentication App that can recognize users using their face or voice. You’ve learned how to work with Python libraries to capture biometric data and create a more secure login system.


Resources and Additional Help


That’s your high school Biometric Authentication App project—have fun securing your app and learning more about biometric technology!

Categorized in: