fixed a bug avoid crack answer
This commit is contained in:
@@ -48,6 +48,7 @@ const WORD_RECORD_MODES: WordRecordModeKey[] = [
|
||||
const ATTEMPT_TTL_MS = 30 * 60 * 1000;
|
||||
const MIN_SECONDS_PER_QUESTION = Number(process.env.VOCABULARY_MIN_SECONDS_PER_QUESTION || 0.4);
|
||||
const ATTEMPT_SECRET = process.env.VOCABULARY_ATTEMPT_SECRET || config.JWT_SECRET;
|
||||
const ANSWER_PROOF_SALT = 'd1ktsalt';
|
||||
|
||||
const isVocabularyTestType = (value: unknown): value is VocabularyTestType => {
|
||||
return value === 'chinese-to-english' ||
|
||||
@@ -104,8 +105,8 @@ const buildAnswerProof = (
|
||||
userAnswer: string,
|
||||
submittedAt: number
|
||||
): string => crypto
|
||||
.createHash('sha256')
|
||||
.update(`${attemptId}:${questionToken}:${submittedAt}:${String(userAnswer ?? '')}`)
|
||||
.createHash('md5')
|
||||
.update(`${ANSWER_PROOF_SALT}:${attemptId}:${questionToken}:${submittedAt}:${String(userAnswer ?? '')}:${ANSWER_PROOF_SALT}`)
|
||||
.digest('hex');
|
||||
|
||||
const buildMultipleChoiceOptions = (word: any, pool: any[]): string[] => {
|
||||
@@ -879,6 +880,7 @@ router.post('/test-record', authMiddleware, async (req, res) => {
|
||||
message: '测试记录已保存',
|
||||
attemptId: attempt._id.toString(),
|
||||
stats: verifiedStats,
|
||||
results: evaluatedResults,
|
||||
submittedAt: new Date(lastSubmittedAtMs)
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user