Passwords for a site with puzzle progression

Viewed 55

I am trying to program my first web-based puzzle game, where the answer to puzzle-one is the key to get to puzzle-2, and so on. I am stuck on how to set "answers" to puzzles that serve as passwords for the next page.

I have thus far considered a javascript code, but nixed it because anyone can see the password via developers' window. .htaccess file was the other viable option, which I am trying with limited success.

Are there other methods to set an answer key to access "page 2" from "page 1", where input area & submit button are embedded within page 1?

1 Answers

You can use Bcrypt to generate a hash from the correct password:

const saltRounds = 10;
const hash = bcrypt.hashSync(correctAnswer, saltRounds);

Then you can check for the answer given by the user:

const resp = bcrypt.compareSync(answer, hash);

If the the answer is the same as the correctAnswer then the function returns true.

Related