Dev.to Security 🔐 Cybersecurity 👁 0 📖 5 min read

Guest ID Verification for Vacation Rentals: Selfie to ID Match in Python

Short-term rental hosts and property managers need to know who is coming before handing over the keys. A guest ID verification step does that remotely: the guest uploads a photo of their ID and a selfie, and your system

Guest ID Verification for Vacation Rentals: Selfie to ID Match in Python

Short-term rental hosts and property managers need to know who is coming before handing over the keys. A guest ID verification step does that remotely: the guest uploads a photo of their ID and a selfie, and your system checks that both show the same person, that the selfie is usable and that the guest meets the minimum age. At arrival, a second check can confirm that the person who booked is really there and that the group is not larger than the booking.

We ran every script on public domain NASA photos: official astronaut portraits play the ID photo (on a sample card marked SPECIMEN), and candid photos from the International Space Station play the selfie.

Want to try it? Get a key for the Face Analyzer API.

The check-in flow

  1. Booking confirmed: the guest gets a link to upload their ID and take a selfie.
  2. Selfie quality gate: exactly one face, no sunglasses, estimated age above your minimum. Otherwise, retake right away.
  3. Face match: the selfie is compared with the face on the ID. Match means verified; no match goes to manual review.
  4. Arrival check (optional): a door camera or check-in tablet photo is compared with the booker's ID to confirm presence and count people.

Results on six check-in attempts

Two genuine guests, one selfie from someone else, a selfie with sunglasses, a group photo sent as a selfie, and a photo with no face. Every attempt got the right decision, and each API call took one to two seconds.

Six pairs of a sample ID card and a selfie with the status returned for each

The ID photos are studio portraits in pressurized suits; the selfies were taken on the space station, in different light and clothing, one with the head tilted sideways and glasses on. Both genuine pairs were matched.

Verify a guest in Python

You need Python 3 with requests and a RapidAPI key in RAPIDAPI_KEY. The script uses /faceanalysis to inspect the selfie and /compare-faces to match it against the ID photo. Save it as guest_check.py:

import os
import requests

HOST = "faceanalyzer-ai.p.rapidapi.com"
HEADERS = {"x-rapidapi-host": HOST, "x-rapidapi-key": os.environ["RAPIDAPI_KEY"]}
MIN_AGE = 25  # many rentals require the main guest to be 25 or older


def call(endpoint, files):
    r = requests.post(f"https://{HOST}/{endpoint}", headers=HEADERS, files=files, timeout=30)
    r.raise_for_status()
    data = r.json()
    if data.get("statusCode") != 200:
        raise RuntimeError(data["body"].get("error", "unknown error"))
    return data["body"]


def check_selfie(selfie_path):
    """Return None if the selfie is usable, or the reason to ask for a new one."""
    with open(selfie_path, "rb") as f:
        faces = call("faceanalysis", {"image": f})["faces"]
    if not faces:
        return "no face found"
    if len(faces) > 1:
        return f"{len(faces)} faces, only the guest should be in the selfie"
    features = faces[0]["facialFeatures"]
    if features["Sunglasses"]:
        return "remove sunglasses"
    if features["AgeRange"]["Low"] < MIN_AGE:
        return "age needs a manual ID check"
    return None


def same_person(id_photo_path, selfie_path):
    with open(id_photo_path, "rb") as a, open(selfie_path, "rb") as b:
        body = call("compare-faces", {"source_image": a, "target_image": b})
    return len(body["matchedFaces"]) > 0


def verify_guest(id_photo_path, selfie_path):
    problem = check_selfie(selfie_path)
    if problem:
        return "retake", problem
    if same_person(id_photo_path, selfie_path):
        return "verified", "selfie matches the ID photo"
    return "manual_review", "selfie does not match the ID photo"


if __name__ == "__main__":
    tests = [
        ("hadfield_card.jpg", "hadfield_selfie.jpg"),
        ("whitson_card.jpg", "whitson_selfie.jpg"),
        ("hadfield_card.jpg", "whitson_selfie.jpg"),
        ("hadfield_card.jpg", "sunglasses_selfie.jpg"),
        ("hadfield_card.jpg", "crew34.jpg"),
        ("hadfield_card.jpg", "nobody.jpg"),
    ]
    for id_photo, selfie in tests:
        status, reason = verify_guest(id_photo, selfie)
        print(f"{id_photo:<18} {selfie:<22} {status:<14} {reason}")
hadfield_card.jpg  hadfield_selfie.jpg    verified       selfie matches the ID photo
whitson_card.jpg   whitson_selfie.jpg     verified       selfie matches the ID photo
hadfield_card.jpg  whitson_selfie.jpg     manual_review  selfie does not match the ID photo
hadfield_card.jpg  sunglasses_selfie.jpg  retake         remove sunglasses
hadfield_card.jpg  crew34.jpg             retake         6 faces, only the guest should be in the selfie
hadfield_card.jpg  nobody.jpg             retake         no face found

The whole ID card is sent as source_image, not a crop: the API finds the face on the card by itself, so the guest can simply photograph the document.

Why three statuses? retake is fixed by the guest in seconds and covers most failures (bad photos, not fraud). manual_review is a usable selfie that does not match: ask for a new upload or a quick video call instead of cancelling. verified unlocks the door code or check-in instructions. The age rule uses AgeRange.Low, the cautious side of the estimate, and only triggers a human look at the date of birth.

Check the group at arrival

One more call answers two questions for hosts worried about extra guests: is the booker in the picture, and how many people are there? compare-faces returns matched and unmatched faces, so the total is the sum of both.

from guest_check import call


def check_group(booker_id_path, group_photo_path, booked_guests):
    """Is the booker in the arrival photo, and how many people are there?"""
    with open(booker_id_path, "rb") as a, open(group_photo_path, "rb") as b:
        body = call("compare-faces", {"source_image": a, "target_image": b})
    people = len(body["matchedFaces"]) + len(body["unmatchedFaces"])
    return {
        "booker_present": len(body["matchedFaces"]) > 0,
        "people_in_photo": people,
        "over_capacity": people > booked_guests,
        "booker_box": body["matchedFaces"][0]["boundingBox"] if body["matchedFaces"] else None,
    }


print(check_group("hadfield_card.jpg", "crew34.jpg", booked_guests=4))
print(check_group("whitson_card.jpg", "crew34.jpg", booked_guests=6))
{'booker_present': True, 'people_in_photo': 6, 'over_capacity': True, 'booker_box': {'topLeft': {'x': 0.31, 'y': 0.42}, 'bottomRight': {'x': 0.37, 'y': 0.54}}}
{'booker_present': False, 'people_in_photo': 6, 'over_capacity': False, 'booker_box': None}

In the official Expedition 34 crew photo, all six astronauts wear sunglasses. The API still found the booker from his ID card and counted six people against a booking for four. With an ID of someone not in the photo, it reported the booker as absent.

Six astronauts wearing sunglasses, the booker framed in green, banner reading 6 people in the photo, booking for 4

Production tips

  • Run the selfie check inside the upload flow, so the guest can retake before leaving the page.
  • Ask for the ID first. If it has no detectable face (glare, blur, a finger), ask for a new picture of the document.
  • Delete images after the decision. Keep the status, date and booking reference.
  • Be transparent about arrival cameras, and never place cameras inside the rental.
  • Need document data too? The eKYC selfie and ID verification guide combines OCR with face matching.

Full tutorial with images: Guest ID Verification for Vacation Rentals on ai-engine.net.

Sources

Try it: grab a key from the Face Analyzer API page and run guest_check.py.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.