Skip to content

Commit

Permalink
add ability to get account hash
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMoonThatRises committed Aug 20, 2024
1 parent 07decc5 commit 13a1483
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
11 changes: 8 additions & 3 deletions Sources/StudentVue/SOAPApi/StudentVueApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions Sources/StudentVue/SOAPApi/Utils/Hash.swift
Original file line number Diff line number Diff line change
@@ -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 ""
}
}
}

Check failure on line 25 in Sources/StudentVue/SOAPApi/Utils/Hash.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)
15 changes: 13 additions & 2 deletions Sources/StudentVue/StudentVue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 13a1483

Please sign in to comment.