diff --git a/Sources/StudentVue/SOAPApi/StudentVueApi.swift b/Sources/StudentVue/SOAPApi/StudentVueApi.swift index 8ddc549..168ccdc 100644 --- a/Sources/StudentVue/SOAPApi/StudentVueApi.swift +++ b/Sources/StudentVue/SOAPApi/StudentVueApi.swift @@ -52,7 +52,7 @@ public class StudentVueApi { /// The username to log into StudentVue's API private var username: String - /// The password to log into StudentVue's API/ + /// The password to log into StudentVue's API private var password: String /// Creates a new URLSession for the library to use @@ -64,8 +64,6 @@ public class StudentVueApi { /// - domain: Domain of the school that uses StudentVue. Should be something like `something.edupoint.com` /// - username: The username of the student's information to access /// - password: The password of the student's information to access - /// - /// - Returns: A new StudentVueApi client public init(domain: String, username: String, password: String) { self.domain = domain @@ -88,6 +86,13 @@ public class StudentVueApi { self.session = URLSession(configuration: sessionConfig) } + /// Retrieves account details as a hash + /// + /// - Returns: Hash of username, password, and domain + internal func getAccountHash() -> String { + return AccountHasher.hash(username: username, password: password, domain: domain) + } + /// Updates the credentials of the user /// /// - Parameters: diff --git a/Sources/StudentVue/SOAPApi/Utils/Hash.swift b/Sources/StudentVue/SOAPApi/Utils/Hash.swift new file mode 100644 index 0000000..2be31dd --- /dev/null +++ b/Sources/StudentVue/SOAPApi/Utils/Hash.swift @@ -0,0 +1,25 @@ +// +// Hash.swift +// StudentVue +// +// Created by TheMoonThatRises on 8/19/24. +// + +import CryptoKit + +class AccountHasher { + public static func hash(username: String, password: String, domain: String) -> String { + if let data = (username + password + domain).data(using: .utf8) { + let digest = SHA256.hash(data: data) + + let hashString = digest + .compactMap { String(format: "%02x", $0) } + .joined() + + return hashString + } else { + return "" + } + } +} + diff --git a/Sources/StudentVue/StudentVue.swift b/Sources/StudentVue/StudentVue.swift index db564ac..22b884f 100644 --- a/Sources/StudentVue/StudentVue.swift +++ b/Sources/StudentVue/StudentVue.swift @@ -21,14 +21,25 @@ public class StudentVue { /// - domain: Domain of the school that uses StudentVue. Should be something like `something.edupoint.com` /// - username: The username of the student's information to access /// - password: The password of the student's information to access - /// - /// - Returns: A new StudentVue client with api and scraper public init(domain: String, username: String, password: String) { StudentVue.domain = domain self.api = StudentVueApi(domain: domain, username: username, password: password) self.scraper = StudentVueScraper(domain: domain, username: username, password: password) } + /// Retrieves account details as a hash + /// + /// - Returns: Hash of username, password, and domain + public func getAccountHash() -> String { + return api.getAccountHash() + } + + /// Updates the credentials of the user + /// + /// - Parameters: + /// - domain: The new domain + /// - username: The new username + /// - password: The new password public func updateCredentials(domain: String? = nil, username: String? = nil, password: String? = nil) { if let domain = domain { StudentVue.domain = domain