forked from Informatiklabor/HS2023-Exercise08
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.ps1
39 lines (32 loc) · 1.17 KB
/
submit.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Check if inside a Git repository
function IsGitRepository {
$currentDir = Get-Location
while ($currentDir -ne [System.IO.Path]::GetPathRoot($currentDir)) {
if (Test-Path (Join-Path $currentDir '.git')) {
return $true
}
$currentDir = [System.IO.DirectoryInfo]$currentDir.Parent
}
return $false
}
if (-not (IsGitRepository)) {
Write-Host "This script must be run inside a Git repository."
Exit
}
# Prompt for the email address
$email = Read-Host -Prompt "Enter your email address"
# Trim and convert the email to lowercase
$email = $email.Trim().ToLower()
# Generate a SHA256 hash of the email
$hasher = [System.Security.Cryptography.SHA256]::Create()
$hashedBytes = $hasher.ComputeHash([Text.Encoding]::UTF8.GetBytes($email))
$hash = [BitConverter]::ToString($hashedBytes) -replace '-', ''
# Create the submissions directory if it doesn't exist
$directory = ".\submissions"
if (-not (Test-Path $directory)) {
New-Item -ItemType Directory -Path $directory
}
# Create a file with the hash as the filename
$file = Join-Path $directory "$hash.txt"
New-Item -Path $file -ItemType File
Write-Host "File created with hash: $hash"