2018-11-19 16:58:23 +01:00
|
|
|
//
|
|
|
|
// NoteBiometricViewController.swift
|
|
|
|
// Friendvatars
|
|
|
|
//
|
|
|
|
// Created by Dawid Kubicki on 19/11/2018.
|
|
|
|
// Copyright © 2018 Razeware. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2018-11-19 23:41:12 +01:00
|
|
|
import KeychainAccess
|
2018-11-19 16:58:23 +01:00
|
|
|
|
2018-11-20 11:29:34 +01:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2018-11-19 16:58:23 +01:00
|
|
|
class NoteBiometricViewController: UIViewController {
|
|
|
|
|
2018-11-19 23:41:12 +01:00
|
|
|
@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")
|
|
|
|
|
2018-11-19 16:58:23 +01:00
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2018-11-19 23:41:12 +01:00
|
|
|
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")
|
|
|
|
}
|
2018-11-19 16:58:23 +01:00
|
|
|
}
|
2018-11-20 11:29:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let secret = randomSecret()
|
|
|
|
|
2018-11-19 23:41:12 +01:00
|
|
|
@IBAction func storeSecret(_ sender: Any) {
|
|
|
|
DispatchQueue.global().async {
|
|
|
|
do {
|
|
|
|
try self.keychain
|
|
|
|
.accessibility(.whenPasscodeSetThisDeviceOnly, authenticationPolicy: .userPresence)
|
2018-11-20 11:29:34 +01:00
|
|
|
.set(self.txtSecret.text!, key: self.secret)
|
2018-11-19 23:41:12 +01:00
|
|
|
} 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ę")
|
2018-11-20 11:29:34 +01:00
|
|
|
.get(self.secret)
|
2018-11-19 23:41:12 +01:00
|
|
|
self.lblSecret.text = "Twoja ukryta notatka to: \(secret!)"
|
|
|
|
} catch let error {
|
|
|
|
print(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-19 16:58:23 +01:00
|
|
|
/*
|
|
|
|
// 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.
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|