Protecting against register account with same fingerprint
This commit is contained in:
parent
322a0b4cb4
commit
3881f37818
5 changed files with 41 additions and 16 deletions
|
@ -18,6 +18,7 @@ public extension Sdk {
|
|||
case noPrivateKey
|
||||
case noSignatureValues
|
||||
case urlError
|
||||
case deviceExist
|
||||
|
||||
case wrongToken
|
||||
case wrongSymbol
|
||||
|
|
|
@ -292,6 +292,7 @@ public class Sdk {
|
|||
case 200: return APIError.wrongToken
|
||||
case -1: return APIError.wrongSymbol //Ya, Vulcan returns -1 code
|
||||
case 203: return APIError.wrongPin
|
||||
case 205: return APIError.deviceExist
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
// Created by Mikołaj on 25/10/2020.
|
||||
//
|
||||
|
||||
|
||||
import SwiftUI
|
||||
import KeychainAccess
|
||||
|
||||
enum AvailableEndpoints: String, CaseIterable {
|
||||
case vulcan = "Vulcan"
|
||||
|
@ -22,7 +22,6 @@ open class Navigation: ObservableObject {
|
|||
}
|
||||
|
||||
struct LoginView: View {
|
||||
|
||||
@StateObject var vulcan: VulcanStore = VulcanStore.shared
|
||||
|
||||
@State private var token: String = ""
|
||||
|
@ -35,6 +34,7 @@ struct LoginView: View {
|
|||
@State private var loginStatus: String = ""
|
||||
@State private var willMoveToNextScreen = false
|
||||
@State private var success = false
|
||||
@State private var showingAlert = false
|
||||
|
||||
let cellHeight: CGFloat = 55
|
||||
let cornerRadius: CGFloat = 12
|
||||
|
@ -58,12 +58,29 @@ struct LoginView: View {
|
|||
case "wrongPin":
|
||||
buttonValue = String(format: NSLocalizedString("\(error)", comment: "loginButton"))
|
||||
|
||||
case "deviceExist":
|
||||
showingAlert.toggle()
|
||||
|
||||
default:
|
||||
buttonValue = String(format: NSLocalizedString("invalidData", comment: "loginButton"))
|
||||
}
|
||||
} else {
|
||||
print("success")
|
||||
success = true
|
||||
let keychain = Keychain()
|
||||
let keyFingerprint = keychain["keyFingerprint"]
|
||||
let allStudentsKeys = keychain["allStudentsKeys"]
|
||||
|
||||
let data = Data(allStudentsKeys!.utf8)
|
||||
do {
|
||||
let array = try JSONSerialization.jsonObject(with: data) as! [String]
|
||||
if array.contains(keyFingerprint!) {
|
||||
showingAlert.toggle()
|
||||
} else {
|
||||
success = true
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,9 +208,12 @@ struct LoginView: View {
|
|||
.frame(maxWidth: .infinity)
|
||||
.background(Color.accentColor.opacity(0.1))
|
||||
.cornerRadius(cornerRadius)
|
||||
}
|
||||
.padding()
|
||||
Spacer()
|
||||
|
||||
}.padding()
|
||||
.alert(isPresented: $showingAlert) {
|
||||
Alert(title: Text("Konto zarejestrowane"), message: Text("Konto zostało już zarejestrowane. Proszę zalogowaź się na inne konto."), dismissButton: .default(Text("OK")))}
|
||||
Spacer()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,17 +21,19 @@ struct AccountManagerView: View {
|
|||
|
||||
//parsing allStudentsKeys to array
|
||||
var allStudents: [String] = []
|
||||
let data = Data(allStudentsKeys.utf8)
|
||||
do {
|
||||
let keys = try JSONSerialization.jsonObject(with: data) as! [String]
|
||||
for key in keys {
|
||||
let student = keychain["student-\(key)"]
|
||||
let data = Data(student!.utf8)
|
||||
let studentParsed = try! JSON(data: data)
|
||||
allStudents.append("\(studentParsed["Login"]["DisplayName"])")
|
||||
if(allStudentsKeys != "[]"){
|
||||
let data = Data(allStudentsKeys.utf8)
|
||||
do {
|
||||
let keys = try JSONSerialization.jsonObject(with: data) as! [String]
|
||||
for key in keys {
|
||||
let student = keychain["student-\(key)"]
|
||||
let data = Data(student!.utf8)
|
||||
let studentParsed = try! JSON(data: data)
|
||||
allStudents.append("\(studentParsed["Login"]["DisplayName"])")
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
|
||||
return allStudents
|
||||
|
|
|
@ -73,6 +73,7 @@ struct ChooseStudentView: View {
|
|||
allStudents.append(keyFingerprint!)
|
||||
keychain["allStudentsKeys"] = "\(allStudents)"
|
||||
|
||||
|
||||
//saving student
|
||||
keychain["student-\(String(describing: keyFingerprint!))"] = "\(json["Envelope"][i])"
|
||||
|
||||
|
|
Loading…
Reference in a new issue