{
  "name": "Information Security with HelmetJS",
  "order": 1,
  "time": "5 hours",
  "helpRoom": "HelpBackend",
  "challenges": [
    {
      "id": "58af07504bbe015e85a91dbd",
      "title": "Introduction to Information Security with HelmetJS Challenges",
      "description": [
        [
          "",
          "",
          "HelmetJS is a type of middleware for Express-based applications that automatically sets HTTP headers to prevent sensitive information from unintentially being passed between the server and client. While HelmetJS does not account for all situations, it does include support for common ones like Content Security Policy, XSS Filtering, and HTTP Strict Transport Security, among others. HelmetJS can be installed on an Express project from npm, after which each layer of protection can be configured to best fit the project.<br><br>Working on these challenges will involve you writing your code on Glitch on our starter project. After completing each challenge you can copy your public glitch url (to the homepage of your app) into the challenge screen to test it! Optionally you may choose to write your project on another platform but it must be publicaly visible for our testing.<br>Start this project on Glitch using <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>this link</a> or clone <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>this repository</a> on GitHub! If you use Glitch, remember to save the link to your project somewhere safe!",
          ""
        ]
      ],
      "releasedOn": "Feb 17, 2017",
      "challengeSeed": [],
      "tests": [],
      "type": "waypoint",
      "challengeType": 7,
      "isRequired": false,
      "translations": {}
    },
    {
      "id": "587d8247367417b2b2512c36",
      "title": "Install and Require Helmet",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "Helmet helps you secure your Express apps by setting various HTTP headers. Install the package, then require it."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "\"helmet\" dependency should be in package.json",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/package.json').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, 'helmet'); }, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8247367417b2b2512c37",
      "title": "Hide Potentially Dangerous Information Using helmet.hidePoweredBy()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "Hackers can exploit known vulnerabilities in Express/Node if they see that your site is powered by Express. X-Powered-By: Express is sent in every request coming from Express by default. The helmet.hidePoweredBy() middleware will remove the X-Powered-By header. You can also explicitly set the header to something else, to throw people off. e.g. app.use(helmet.hidePoweredBy({ setTo: 'PHP 4.2.0' }))"
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.hidePoweredBy() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'hidePoweredBy'); assert.notEqual(data.headers['x-powered-by'], 'Express')}, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8247367417b2b2512c38",
      "title": "Mitigate the Risk of Clickjacking with helmet.frameguard()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "Your page could be put in a <frame> or <iframe> without your consent. This can result in clickjacking attacks, among other things. Clickjacking is a technique of tricking a user into interacting with a page different from what the user thinks it is. This can be obtained executing your page in a malicious context, by mean of iframing. In that context a hacker can put a hidden layer over your page. Hidden buttons can be used to run bad scripts. This middleware sets the X-Frame-Options header. It restricts who can put your site in a frame. It has three modes: DENY, SAMEORIGIN, and ALLOW-FROM.",
        "We don’t need our app to be framed. You should use helmet.frameguard() passing with the configuration object {action: 'deny'}."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.frameguard() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'frameguard', 'helmet.frameguard() middleware is not mounted correctly'); }, xhr => { throw new Error(xhr.responseText); })"
        },
        {
          "text": "helmet.frameguard() 'action' should be set to 'DENY'",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.property(data.headers, 'x-frame-options'); assert.equal(data.headers['x-frame-options'], 'DENY');}, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8247367417b2b2512c39",
      "title": "Mitigate the Risk of Cross Site Scripting (XSS) Attacks with helmet.xssFilter()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "Cross-site scripting (XSS) is a frequent type of attack where malicious scripts are injected into vulnerable pages, with the purpose of stealing sensitive data like session cookies, or passwords.",
        "The basic rule to lower the risk of an XSS attack is simple: “Never trust user’s input”. As a developer you should always sanitize all the input coming from the outside. This includes data coming from forms, GET query urls, and even from POST bodies. Sanitizing means that you should find and encode the characters that may be dangerous e.g. <, >.",
        "Modern browsers can help mitigating the risk by adopting better software strategies. Often these are configurable via http headers.",
        "The X-XSS-Protection HTTP header is a basic protection. The browser detects a potential injected script using a heuristic filter. If the header is enabled, the browser changes the script code, neutralizing it.",
        "It still has limited support."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.xssFilter() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'xXssProtection'); assert.property(data.headers, 'x-xss-protection'); }, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8248367417b2b2512c3a",
      "title": "Avoid Inferring the Response MIME Type with helmet.noSniff()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "Browsers can use content or MIME sniffing to adapt to different datatypes coming from a response. They override the Content-Type headers to guess and process the data. While this can be convenient in some scenarios, it can also lead to some dangerous attacks. This middleware sets the X-Content-Type-Options header to nosniff. This instructs the browser to not bypass the provided Content-Type."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.noSniff() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'nosniff'); assert.equal(data.headers['x-content-type-options'], 'nosniff'); }, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8248367417b2b2512c3b",
      "title": "Prevent IE from Opening Untrusted HTML with helmet.ieNoOpen()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "Some web applications will serve untrusted HTML for download. Some versions of Internet Explorer by default open those HTML files in the context of your site. This means that an untrusted HTML page could start doing bad things in the context of your pages. This middleware sets the X-Download-Options header to noopen. This will prevent IE users from executing downloads in the trusted site’s context."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.ieNoOpen() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'ienoopen'); assert.equal(data.headers['x-download-options'], 'noopen'); }, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8248367417b2b2512c3c",
      "title": "Ask Browsers to Access Your Site via HTTPS Only with helmet.hsts()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "HTTP Strict Transport Security (HSTS) is a web security policy which helps to protect websites against protocol downgrade attacks and cookie hijacking. If your website can be accessed via HTTPS you can ask user’s browsers to avoid using insecure HTTP. By setting the header Strict-Transport-Security, you tell the browsers to use HTTPS for the future requests in a specified amount of time. This will work for the requests coming after the initial request.",
        "Configure helmet.hsts() to use HTTPS for the next 90 days. Pass the config object {maxAge: timeInMilliseconds, force: true}. Glitch already has hsts enabled. To override its settings you need to set the field \"force\" to true in the config object. We will intercept and restore the Glitch header, after inspecting it for testing.",
        "Note: Configuring HTTPS on a custom website requires the acquisition of a domain, and a SSL/TSL Certificate."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.hsts() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'hsts'); assert.property(data.headers, 'strict-transport-security'); }, xhr => { throw new Error(xhr.responseText); })"
        },
        {
          "text": "maxAge should be equal to 7776000 ms (90 days)",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.match(data.headers['strict-transport-security'], /^max-age=777600000;?/); }, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8248367417b2b2512c3d",
      "title": "Disable DNS Prefetching with helmet.dnsPrefetchControl()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "To improve performance, most browsers prefetch DNS records for the links in a page. In that way the destination ip is already known when the user clicks on a link. This may lead to over-use of the DNS service (if you own a big website, visited by millions people…), privacy issues (one eavesdropper could infer that you are on a certain page), or page statistics alteration (some links may appear visited even if they are not). If you have high security needs you can disable DNS prefetching, at the cost of a performance penalty."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.dnsPrefetchControl() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'dnsPrefetchControl'); assert.equal(data.headers['x-dns-prefetch-control'], 'off'); }, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8249367417b2b2512c3e",
      "title": "Disable Client-Side Caching with helmet.noCache()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "If you are releasing an update for your website, and you want the users to always download the newer version, you can (try to) disable caching on client’s browser. It can be useful in development too. Caching has performance benefits, which you will lose, so only use this option when there is a real need."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.noCache() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'nocache'); assert.equal(data.headers['cache-control'], 'no-store, no-cache, must-revalidate, proxy-revalidate'); }, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8249367417b2b2512c3f",
      "title": "Set a Content Security Policy with helmet.contentSecurityPolicy()",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "This challenge highlights one promising new defense that can significantly reduce the risk and impact of many type of attacks in modern browsers. By setting and configuring a Content Security Policy you can prevent the injection of anything unintended into your page. This will protect your app from XSS vulnerabilities, undesired tracking, malicious frames, and much more. CSP works by defining a whitelist of content sources which are trusted. You can configure them for each kind of resource a web page may need (scripts, stylesheets, fonts, frames, media, and so on…). There are multiple directives available, so a website owner can have a granular control. See HTML 5 Rocks, KeyCDN for more details. Unfortunately CSP in unsupported by older browser.",
        "By default, directives are wide open, so it’s important to set the defaultSrc directive as a fallback. Helmet supports both defaultSrc and default-src naming styles. The fallback applies for most of the unspecified directives. In this exercise, use helmet.contentSecurityPolicy(), and configure it setting the defaultSrc directive to [\"self\"] (the list of allowed sources must be in an array), in order to trust only your website address by default. Set also the scriptSrc directive so that you will allow scripts to be downloaded from your website, and from the domain 'trusted-cdn.com'.",
        "Hint: in the \"'self'\" keyword, the single quotes are part of the keyword itself, so it needs to be enclosed in double quotes to be working."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "helmet.csp() middleware should be mounted correctly",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { assert.include(data.appStack, 'csp'); }, xhr => { throw new Error(xhr.responseText); })"
        },
        {
          "text": "Your csp config is not correct. defaultSrc should be [\"'self'\"] and scriptSrc should be [\"'self'\", 'trusted-cdn.com']",
          "testString": "getUserInput => $.get(getUserInput('url') + '/_api/app-info').then(data => { var cspHeader = Object.keys(data.headers).filter(function(k){ return k === 'content-security-policy' || k === 'x-webkit-csp' || k === 'x-content-security-policy' })[0]; assert.equal(data.headers[cspHeader], \"default-src 'self'; script-src 'self' trusted-cdn.com\"); }, xhr => { throw new Error(xhr.responseText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "587d8249367417b2b2512c40",
      "title": "Configure Helmet Using the ‘parent’ helmet() Middleware",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-infosec/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-infosec/'>GitHub</a>.",
        "app.use(helmet()) will automatically include all the middleware introduced above, except noCache(), and contentSecurityPolicy(), but these can be enabled if necessary. You can also disable or configure any other middleware individually, using a configuration object.",
        "// Example",
        "<code>app.use(helmet({</code>",
        "<code>  frameguard: {         // configure</code>",
        "<code>    action: 'deny'</code>",
        "<code>  },</code>",
        "<code>  contentSecurityPolicy: {    // enable and configure</code>",
        "<code>   directives: {</code>",
        "<code>     defaultSrc: [\"self\"],</code>",
        "<code>     styleSrc: ['style.com'],</code>",
        "<code>   }</code>",
        "<code>  },</code>",
        "<code> dnsPrefetchControl: false     // disable</code>",
        "<code>}))</code>",
        "We introduced each middleware separately for teaching purpose, and for ease of testing. Using the ‘parent’ helmet() middleware is easiest, and cleaner, for a real project."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "no tests - it's a descriptive challenge",
          "testString": "assert(true)"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "58a25bcef9fc0f352b528e7b",
      "title": "Protect Your Data with BCrypt",
      "description": [
        [
          "",
          "",
          "The safest way to protect a password is to never even store it- even encrypted. The solution to this security problem is hashing. Unlike encryptions, hashes cannot be transformed back into the original data. So how do you use a hash? A hash is used to verify data like a password again at a later point in time without actually knowing what it is in the future by hashing the entered password in the same manner as the original and comparing the results; if they match then you can be sure it is the same data. A widely used library for this is <em>BCrypt</em>. With how easy BCrypt is to implement into your web applications, you should never have any excuse to store a plain text password in your databases.<br>Start this project on Glitch using <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-bcrypt/'>this link</a> or clone <a href='https://github.com/freeCodeCamp/boilerplate-bcrypt/'>this repository</a> on GitHub! If you use Glitch, remember to save the link to your project somewhere safe.",
          ""
        ]
      ],
      "releasedOn": "",
      "challengeSeed": [],
      "tests": [],
      "type": "Waypoint",
      "challengeType": 7,
      "isRequired": false,
      "titleEs": "",
      "descriptionEs": [
        []
      ],
      "titleFr": "",
      "descriptionFr": [
        []
      ],
      "titleDe": "",
      "descriptionDe": [
        []
      ]
    },
    {
      "id": "58a25bcef9fc0f352b528e7c",
      "title": "Understand BCrypt Hashes",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-bcrypt/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-bcrypt/'>GitHub</a>.",
        "BCrypt hashes are very secure. A hash is basically a fingerprint of the original data- always unique. This is accomplished by feeding the original data into a algorithm and having returned a fixed length result. To further complicate this process and make it more secure, you can also <em>salt</em> your hash. Salting your hash involves adding random data to the original data before the hashing process which makes it even harder to crack the hash.",
        "BCrypt hashes will always looks like <code>$2a$13$ZyprE5MRw2Q3WpNOGZWGbeG7ADUre1Q8QO.uUUtcbqloU0yvzavOm</code> which does have a structure. The first small bit of data <code>$2a</code> is defining what kind of hash algorithm was used. The next portion <code>$13</code> defines the <em>cost</em>. Cost is about how much power it takes to compute the hash. It is on a logarithmic scale of 2^cost and determines how many times the data is put through the hashing algorithm. For example, at a cost of 10 you are able to hash 10 passwords a second on an average computer, however at a cost of 15 it takes 3 seconds per hash... and to take it further, at a cost of 31 it would takes multiple days to complete a hash. A cost of 12 is considered very secure at this time. The last portion of your hash <code>$ZyprE5MRw2Q3WpNOGZWGbeG7ADUre1Q8QO.uUUtcbqloU0yvzavOm</code>, looks like 1 large string of numbers, periods, and letters but it is actually 2 separate pieces of information. The first 22 characters is the salt in plain text, and the rest is the hashed password!",
        "<hr>To begin using BCrypt, add it as a dependency in your project and require it as 'bcrypt' in your server.",
        "Submit your page when you think you've got it right."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "BCyrpt is a dependency",
          "testString": "getUserInput => $.get(getUserInput('url')+ '/_api/package.json') .then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, 'bcrypt', 'Your project should list \"bcrypt\" as a dependency'); }, xhr => { throw new Error(xhr.statusText); })"
        },
        {
          "text": "BCrypt has been properly required",
          "testString": "getUserInput => $.get(getUserInput('url')+ '/_api/server.js').then(data => {assert.match(data, /bcrypt.*=.*require.*('|\")bcrypt('|\")/gi, 'You should correctly require and instanciate socket.io as io.');}, xhr => { throw new Error(xhr.statusText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "58a25bcff9fc0f352b528e7d",
      "title": "Hash and Compare Passwords Asynchronously",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-bcrypt/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-bcrypt/'>GitHub</a>.",
        "As hashing is designed to be computationally intensive, it is recommended to do so asyncronously on your server as to avoid blocking incoming connections while you hash. All you have to do to hash a password asynchronous is call <code>bcrypt.hash(myPlaintextPassword, saltRounds, (err, hash) => { /*Store hash in your db*/ });</code>",
        "<hr>Add this hashing function to your server(we've already defined the variables used in the function for you to use) and log it to the console for you to see! At this point you would normally save the hash to your database.",
        "Now when you need to figure out if a new input is the same data as the hash you would just use the compare function <code>bcrypt.compare(myPlaintextPassword, hash, (err, res) => { /*res == true or false*/ });</code>. Add this into your existing hash function(since you need to wait for the hash to complete before calling the compare function) after you log the completed hash and log 'res' to the console within the compare. You should see in the console a hash then 'true' is printed! If you change 'myPlaintextPassword' in the compare function to 'someOtherPlaintextPassword' then it should say false.",
        "<pre>bcrypt.hash('passw0rd!', 13, (err, hash) => {\n  console.log(hash); //$2a$12$Y.PHPE15wR25qrrtgGkiYe2sXo98cjuMCG1YwSI5rJW1DSJp0gEYS\n  bcrypt.compare('passw0rd!', hash, (err, res) => {\n      console.log(res); //true\n  });\n});</pre>",
        "Submit your page when you think you've got it right."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "Async hash generated and correctly compared",
          "testString": "getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /START_ASYNC[^]*bcrypt.hash.*myPlaintextPassword( |),( |)saltRounds( |),( |).*err( |),( |)hash[^]*END_ASYNC/gi, 'You should call bcrypt.hash on myPlaintextPassword and saltRounds and handle err and hash as a result in the callback'); assert.match(data, /START_ASYNC[^]*bcrypt.hash[^]*bcrypt.compare.*myPlaintextPassword( |),( |)hash( |),( |).*err( |),( |)res[^]*}[^]*}[^]*END_ASYNC/gi, 'Nested within the hash function should be the compare function comparing myPlaintextPassword to hash'); }, xhr => { throw new Error(xhr.statusText); })"
        }
      ],
      "solutions": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    },
    {
      "id": "58a25bcff9fc0f352b528e7e",
      "title": "Hash and Compare Passwords Synchronously",
      "description": [
        "As a reminder, this project is being built upon the following starter project on <a href='https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-bcrypt/'>Glitch</a>, or cloned from <a href='https://github.com/freeCodeCamp/boilerplate-bcrypt/'>GitHub</a>.",
        "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 <code>var hash = bcrypt.hashSync(myPlaintextPassword, saltRounds);</code>",
        "<hr>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 wont 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: <code>var result = bcrypt.compareSync(myPlaintextPassword, hash);</code> with the result being a boolean true or false. Add this function in and log to the console the result to see it working.",
        "Submit your page when you think you've got it right. If you ran into errors during these challenges you can take a look at the example completed code <a href='https://gist.github.com/JosephLivengood/9a2698fb63e42d9d8b4b84235c08b4c4'>here</a>."
      ],
      "challengeSeed": [],
      "tests": [
        {
          "text": "Sync hash generated and correctly compared",
          "testString": "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": [],
      "hints": [],
      "type": "backend",
      "releasedOn": "Feb 17, 2017",
      "challengeType": 0,
      "translations": {}
    }
  ]
}
