Skip to content

Commit 12a4eeb

Browse files
Prepare to add a hash function
Signed-off-by: David A. Wheeler <[email protected]>
1 parent ebdf533 commit 12a4eeb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

docs/labs/checker.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ function findIndexes(form) {
227227
}
228228
}
229229

230+
function makeStamp() {
231+
let timeStamp = (new Date()).toISOString();
232+
let uuid = crypto.randomUUID();
233+
let resultBeginning = `${timeStamp} ${uuid}`;
234+
return resultBeginning;
235+
// TODO: Add hash. JavaScript has such a function
236+
// in the browser, but it's only available in secure contexts and
237+
// returns a promise, so it's not clear we should use it.
238+
// let digestHex = digestMessage(resultBeginning);
239+
// let digestEnding = digestHex.slice(-8);
240+
// return `${resultBeginning} ${digestEnding}`;
241+
}
242+
230243
/**
231244
* Check the document's user input "attempt" to see if matches "correct".
232245
* Then set "grade" in document depending on that answer.
@@ -254,9 +267,7 @@ function runCheck() {
254267
// This makes it easy to detect someone simply copying a final result.
255268
correctStamp = document.getElementById('correctStamp');
256269
if (correctStamp) {
257-
let timeStamp = (new Date()).toISOString();
258-
let uuid = crypto.randomUUID();
259-
correctStamp.innerHTML = `${timeStamp} ${uuid}`;
270+
correctStamp.innerHTML = makeStamp();
260271
}
261272

262273
// Use a timeout so the underlying page will *re-render* before the

0 commit comments

Comments
 (0)