|
- <%
-
- Function HashPassword(password)
- Dim shell, command, execObj, outputLine, result
-
- ' Create Shell Object
- Set shell = CreateObject("WScript.Shell")
-
- ' Construct PowerShell Command
-
- command = "cmd /c powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -File """ & Server.MapPath(".") & "..\Core\hash_sha256.ps1"" -password " & password
- ' Execute Command
- Set execObj = shell.Exec(command)
-
- ' Read Output
- Do While Not execObj.StdOut.AtEndOfStream
- outputLine = Trim(execObj.StdOut.ReadAll())
- If outputLine <> "" Then
- result = outputLine ' Capture the hash
- End If
- Loop
-
- ' Cleanup
- Set shell = Nothing
- Set execObj = Nothing
-
- ' Return the hash or error message
- If result = "" Or Left(result, 5) = "ERROR" Then
- HashPassword = result ' "ERROR: Hash not generated"
- Else
- HashPassword = result
- End If
- End Function
-
- Function CheckPassword(username, password)
- Dim user,UsersRepository
- Set UsersRepository = CreateRepository(conn, "Users", "UserId")
- ' Find User
- Set User = UsersRepository.Find(Array("UserName", user), Empty)
- If user Is Nothing Then Exit Function ' Implicitly returns False
-
- ' Compare Hashed Password
- CheckPassword = (HashPassword(password) = user.PasswordHash)
- End Function
- %>
|