Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Ben Os
Ben Os
20,008 Points

What is hash salting in the context Dave McFarland is referring to?

I took this video explaining hashing and salting under the course User Authentication With Express and Mongo.

  • I understand that a hash is a representation of a password stored in the DB used to prevent say company workers from copying password (the hash will be suited to a password given in authentication) and created by passing the password in a hash function (simple hash function in this case).

  • I also understand that salting a hash is randomizing the hash.

What I didn't understand from the video is how would an hash keep being evaluated properly if we change it (salting it), each authentication anew. In other words, how could it still match the password.

Dave McFarland

2 Answers

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Sorry for the late response Ben Aharoni -- I wrote up an answer last week, but didn't hit the "Post Answer" button :(

So the salt is a randomized bit of data used to hash the password -- without the salt, someone with access to the database could create multiple accounts with different passwords. They could then search the database of users for the exact hashed passwords that match the accounts they created. Even though they couldn't break the hash and decrypt the other person's password, they'de know what it is because they'd typed the same thing.

The salt makes sure that each hashed password is unique. The salt is stored with the hashed password. The salt doesn’t change for each individual user password, unless they create a new password (then a new randomized salt is used). So each time a user logs in, the app uses the original salt to create a hash with the user input and compares that to the value stored in the database. If the new hashed value matches the one in the database, then they can log in.

Here’s another video about Hashing from one of our courses: Introduction to Data Security

Ben Os
Ben Os
20,008 Points

I've opened a question on this in Cryptography StackExchange and answers are available here

Though, this is a very complicated issue and some answers there are bad in the sense they are not didactic and Dave McFarland it is best you will explain this here I think for all students stuck in that video because I don't think any person can really explain this in a few words but rather in a bit more longer explanation.