Skip to content
/ GEM Public

:octocat: Two-factor authentication login iOS application.

Notifications You must be signed in to change notification settings

emreozdil/GEM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GEM Travis CI

Introduction

Two-factor authentication login application.

  1. Email and password authentication via Firebase
  2. Facial authentication verifies whether the database view and the current view are the same via Microsoft Face API

Requirements

  • Swift 4.2
  • Xcode 10.0+
  • Firebase
  • ProjectOxfordFace (Microsoft Face API)

Usage

Modify project settings and API functions

  • Create Firebase Project for email and password authentication
  • Change GoogleService-Info.plist
  • Change Microsoft Face API key

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

Then, run the following command:

$ pod install

Change bundle identifier and development team

Firebase and ProjectOxfordFace

Using Firebase back-end API and ProjectOxfordFace Face API

Set Your Own Face API Key

let client = MPOFaceServiceClient(subscriptionKey: "Microsoft Face API KEY")!

Registration

User authentication, add to database and store of photo

Register User
Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
}
User Added to Database
guard let uid = user?.uid else {
    return
}
let ref = Database.database().reference(fromURL: "FIREBASE_URL")
let userReference = ref.child("users").child(uid)

let values = [
    "name": name,
    "email": email,
    "password": shaHex // sha256 password
]
userReference.updateChildValues(values, withCompletionBlock: { (error, reference) in
}
User Photo Detect and Save Storage
let userID = Auth.auth().currentUser?.uid
let imageRef = usersStorageRef.child("\(userID!).jpg")

client.detect(with: data!, returnFaceId: true, returnFaceLandmarks: true, returnFaceAttributes: [], completionBlock: { (faces, error) in

    let uploadTask = imageRef.putData(dataImage, metadata: nil, completion: { (metadata, error) in

    })

    uploadTask.resume()

})

Login

User authentication, verify between storage photo and real-time photo

Login User
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
}
Verify Photos
var faceFromPhoto: MPOFace!
var faceFromFirebase: MPOFace!

// Detect real-time photo
client.detect(with: data, returnFaceId: true, returnFaceLandmarks: true, returnFaceAttributes: [], completionBlock: { (faces, error) in
  self.faceFromPhoto = faces![0]

  // Detect storage photo
  client.detect(withUrl: url, returnFaceId: true, returnFaceLandmarks: true, returnFaceAttributes: [], completionBlock: { (faces, error) in
      self.faceFromFirebase = faces![0]

        // Verify photos
        client.verify(withFirstFaceId: self.faceFromPhoto.faceId, faceId2: self.faceFromFirebase.faceId, completionBlock: { (result, error) in
            if result!.isIdentical {
                // THE PERSON IS THE SAME
                // Open logged in view
            }
        })
    })
})