85 lines
2.4 KiB
Swift
85 lines
2.4 KiB
Swift
//
|
|
// NoteBiometricViewController.swift
|
|
// Friendvatars
|
|
//
|
|
// Created by Dawid Kubicki on 19/11/2018.
|
|
// Copyright © 2018 Razeware. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import KeychainAccess
|
|
|
|
func randomSecret(length: Int = 10) -> String {
|
|
let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
var randomString: String = ""
|
|
|
|
for _ in 0..<length {
|
|
let randomValue = arc4random_uniform(UInt32(base.count))
|
|
randomString += "\(base[base.index(base.startIndex, offsetBy: Int(randomValue))])"
|
|
}
|
|
return randomString.sha1()
|
|
}
|
|
|
|
class NoteBiometricViewController: UIViewController {
|
|
|
|
@IBAction func isSignOut(_ sender: Any) {
|
|
try? AuthController.signOut()
|
|
}
|
|
@IBOutlet weak var txtSecret: UITextField!
|
|
@IBOutlet weak var imgBio: UIImageView!
|
|
@IBOutlet weak var lblSecret: UILabel!
|
|
|
|
let keychain = Keychain(service: "com.dawidkubicki.Friendvatars")
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
if(biometricType == .touchID) {
|
|
imgBio.image = UIImage(named: "TouchID")
|
|
} else if(biometricType == .faceID) {
|
|
imgBio.image = UIImage(named: "FaceID")
|
|
} else if(biometricType == .none) {
|
|
print("Nie ma możliwości użycia biometrycznego uwierzytelniania")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let secret = randomSecret()
|
|
|
|
@IBAction func storeSecret(_ sender: Any) {
|
|
DispatchQueue.global().async {
|
|
do {
|
|
try self.keychain
|
|
.accessibility(.whenPasscodeSetThisDeviceOnly, authenticationPolicy: .userPresence)
|
|
.set(self.txtSecret.text!, key: self.secret)
|
|
} catch let error {
|
|
print(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
@IBAction func getSecret(_ sender: Any) {
|
|
DispatchQueue.global().async {
|
|
do {
|
|
let secret = try self.keychain
|
|
.authenticationPrompt("Zaloguj się biometrycznie, aby zobaczyć notatkę")
|
|
.get(self.secret)
|
|
self.lblSecret.text = "Twoja ukryta notatka to: \(secret!)"
|
|
} catch let error {
|
|
print(error)
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
// MARK: - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
// Get the new view controller using segue.destination.
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
|
|
}
|