Skip to content

Commit

Permalink
Added config file and session auth
Browse files Browse the repository at this point in the history
  • Loading branch information
boltgolt committed Jan 5, 2018
1 parent 4b3f306 commit 4d3d0d4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,8 @@ ENV/
# mypy
.mypy_cache/

# Ignore generated models
# generated models
/models

# config file
config.py
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ubuntu Howdy

Windows Hello™ style authentication for Ubuntu

Notes:

tail /var/log/auth.log

/etc/pam.d/sudo
auth sufficient pam_python.so /path/to/pam.py
18 changes: 8 additions & 10 deletions compair.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,31 @@
import sys
import os

import config

def stop(status):
video_capture.release()
sys.exit(status)

path = ""
distance = 3

try:
if not isinstance(sys.argv[1], str):
sys.exit(1)
except IndexError:
sys.exit(1)

user = sys.argv[1]

# Get a reference to webcam #0 (the default one)
video_capture = cv2.VideoCapture(1)
video_capture = cv2.VideoCapture(config.device_id)

encodings = []

try:
for exposure in ["L", "M", "S"]:
ref = face_recognition.load_image_file(path + "/" + user + "/" + exposure + ".jpg")
ref = face_recognition.load_image_file(os.path.dirname(__file__) + "/models/" + user + "/" + exposure + ".jpg")
enc = face_recognition.face_encodings(ref)[0]
encodings.append(enc)
except FileNotFoundError:
stop(802)
stop(10)

tries = 0

Expand All @@ -44,10 +42,10 @@ def stop(status):
matches = face_recognition.face_distance(encodings, face_encoding)

for match in matches:
if match < distance:
if match < config.certainty:
stop(0)

if tries => 100:
stop(801)
if tries > config.frame_count:
stop(11)

tries += 1
10 changes: 10 additions & 0 deletions config_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The certainty of the detected face belonging to the user of the account
# On a scale from 1 to 10, values above 5 are not recomended
certainty = 3

# The number of frames to capture and to process before timing out
frame_count = 120

# The /dev/videoX id to capture frames from
# On my laptop, video0 is the normal camera and video1 is the IR version
device_id = 1
25 changes: 19 additions & 6 deletions pam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@
import sys
import os

def pam_sm_authenticate(pamh, flags, args):
status = subprocess.call(["python3", "compair.py", pamh.get_user()])
def doAuth(pamh):
status = subprocess.call(["python3", "/compair.py", pamh.get_user()])

if status == 801:
print("Timeout reached, ould not find a known face")
if status == 10:
print("No face model is known for this user, aborting")
return pamh.PAM_SYSTEM_ERR
if status == 34:
print("No face model is known for this user")
if status == 11:
print("Timeout reached, ould not find a known face")
return pamh.PAM_SYSTEM_ERR
if status == 0:
print("Identified face as " + os.environ.get("USER"))
return pamh.PAM_SUCCESS

print(status)
return pamh.PAM_SYSTEM_ERR

def pam_sm_authenticate(pamh, flags, args):
return doAuth(pamh)

def pam_sm_open_session(pamh, flags, args):
return doAuth(pamh)

def pam_sm_close_session(pamh, flags, argv):
return pamh.PAM_SUCCESS

def pam_sm_setcred(pamh, flags, argv):
return pamh.PAM_SUCCESS

0 comments on commit 4d3d0d4

Please sign in to comment.