Can add the token by clicking on the Authorize button in. The token is added to your request so that you can query the protected endpoint. Note that you can generate a token by sending a request to the endpoint using valid and . Try it yourself. Authentication workflows in Hashed Passwords currently store this field in plain text. This is a security risk because if the database is compromised all passwords are also compromised. To solve this problem you can hash the password before storing it in the database. You can hash passwords using a cryptographic library. Install it Copy First you will update the and method in to hash the password before storing it in the database Copy This function accepts two parameters the input string to the hash function and the number of hashing rounds also known as the cost factor. Increasing the number of hashing rounds increases the time required to calculate the hash. There is a trade-off between security and performance here. The more hashing rounds the longer it takes to calculate the hash value which helps prevent brute force attacks.
However, more rounds of hashing also means more time is needed to calculate the hash when a user logs in. This Stack Overflow answer has a good discussion of this topic. Another technique called salting is also automatically used to make it more dif photo editing servies ficult to brute force the hash. Salting is a technique that adds a random string of characters to an input string before hashing it. This way an attacker cannot use a precomputed hash table to crack passwords because each password has a different salt value. You will also need to update the database seed script to hash the password before inserting it into the database. Copy Run the seed script and you should see that the passwords stored in the database are now hashed. The value of this field will be different for you because a different salt value is used each time. What's important is that the value is now a hashed string.
Now if you try to use correct password you will face error. compare the clear text password in the user's request with the hashed password in the database. Updated method to use hashed password copy You can now log in with the correct password and get it in the response. Summary and Final Comments In this chapter you learned how to implement authentication in . You also learned about salting passwords and integrating authentication with. You can find the completed code for this tutorial in a branch of the repository. If you find an issue please feel free to raise an issue or commit in the repository. You can also contact me directly on . Education Don’t miss the next article The Ultimate Guide to Testing Pipeline Series Sabine Adams Sabine Adams Sabine Dev Continuous .