Files
GM Fuster 3b056aa7b4 chore(replit): use correct brand name across codebase (#41941)
* replace repl.it with replit.com in the English version

Replace repl.it to replit.com in the English version.  Chinese and Spanish versions have the same issue.

* Updated the repl.it to replit.com or Replit

I changed the text from replit.com to Replit and added the changes to the files outside the curriculum folder.

* Forgot removing one .com.

There was on Replit.com that I missed when I reviewed the files.

* Resolve conflicts

I got an unable to auto merge so resolving conflicts and trying again.

* try committing conflicts again

* Trying the conflicts again

* chore: fix typo in personal library

Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>

Co-authored-by: gemmaf98 <44875585+gemmaf98@users.noreply.github.com>
Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>
2021-04-29 11:13:38 +01:00

2.3 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
58a25bcff9fc0f352b528e7e Hash and Compare Passwords Synchronously 2 301579 hash-and-compare-passwords-synchronously

--description--

As a reminder, this project is being built upon the following starter project on Replit, or cloned from GitHub.

Hashing synchronously is just as easy to do but can cause lag if using it server side with a high cost or with hashing done very often. Hashing with this method is as easy as calling

var hash = bcrypt.hashSync(myPlaintextPassword, saltRounds);

Add this method of hashing to your code and then log the result to the console. Again, the variables used are already defined in the server so you won't need to adjust them. You may notice even though you are hashing the same password as in the async function, the result in the console is different- this is due to the salt being randomly generated each time as seen by the first 22 characters in the third string of the hash. Now to compare a password input with the new sync hash, you would use the compareSync method:

var result = bcrypt.compareSync(myPlaintextPassword, hash);

with the result being a boolean true or false.

--instructions--

Add the function in and log the result to the console to see it working.

Submit your page when you think you've got it right.

--hints--

Sync hash should be generated and correctly compared.

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/server.js').then(
    (data) => {
      assert.match(
        data,
        /START_SYNC[^]*hash.*=.*bcrypt.hashSync.*myPlaintextPassword( |),( |)saltRounds[^]*END_SYNC/gi,
        'You should call bcrypt.hashSync on myPlaintextPassword with saltRounds'
      );
      assert.match(
        data,
        /START_SYNC[^]*result.*=.*bcrypt.compareSync.*myPlaintextPassword( |),( |)hash[^]*END_SYNC/gi,
        'You should call bcrypt.compareSync on myPlaintextPassword with the hash generated in the last line'
      );
    },
    (xhr) => {
      throw new Error(xhr.statusText);
    }
  );

--solutions--

/**
  Backend challenges don't need solutions, 
  because they would need to be tested against a full working project. 
  Please check our contributing guidelines to learn more.
*/